-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Type inference of integer literals: inconsistency with the reference #41060
Copy link
Copy link
Closed
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Metadata
Metadata
Assignees
Labels
A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsArea: Documentation for any part of the project, including the compiler, standard library, and toolsA-inferenceArea: Type inferenceArea: Type inferenceC-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.
Type
Fields
Give feedbackNo fields configured for issues without a type.
The reference currently says the following for integer literals
This does however not work for some inherent methods of signed integer types:
As you can see,
zis under-constrained in this case. The compiler does the right thing and defaults to typei32, so calling the trait methodwhat_type()works.If you uncomment the inherent method call to
is_positive(),zstill is under-constrained in pretty much the same way as before, however, the compiler fails to default toi32and instead printsAlso note that the reference says
But the following example show that the order of statements is important:
I think floating-point literals have the same issue, but I haven't checked.
Issue #39255 and issue #40985 may be related.