-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Diagnostics for ambiguous number types could be better #40985
Copy link
Copy link
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.WG-diagnosticsWorking group: DiagnosticsWorking group: Diagnostics
Type
Fields
Give feedbackNo fields configured for issues without a type.
Ambiguous integer or float type variable can lead to some rather confusing error messages. Consider:
Method calls on an ambiguous number type
The first error says that
{float}doesn't have a method calledpowi, but taken naively that's not true: bothf32andf64have methodspowi. The actual problem is that the type inference doesn't know which floating point type the user wants.The
helpis even more confusing, because it suggests the user to use a deprecated trait that's not even documented anymore.Casting an ambiguous number type
Likewise, when casting one could again run into the same problem. Here, it complains that the cast is "non-scalar" but naively
{float}sounds like a perfectly scalar type! In reality the problem is that casting requires the source type to be non-ambiguous.Suggestion
Tentative PR: master...Rufflewind:ambiguous-number-type
Tweak the error messages a bit when the type is
{float}or{integer}. Also, perhaps suggestions for deprecated traits could be suppressed?