You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When assigning to an int using min/max and number literals alone, it's possible to determine that max(7.1, 10) is always assignable to int at compile time, and that max(5, 7.1) is not. This is what the compiler indeed seems to do.
So I experimented mixing that in various combinations with an int var, as below:
funcmain() {
varsomeNumint=50// Normal mixing of number literals// var m int = max(7.1, 10) // Expected: 10// var m int = max(5, 7.1) // Expected error: cannot use max(5, 7.1) (untyped float constant 7.1) as int value in variable declaration (truncated)// Expected errors:// var m int = min(7.1, 10, someNum) // 7.1 (untyped float constant) truncated to int// var m int = max(5, 7.1, someNum) // 7.1 (untyped float constant) truncated to int// Compile assertion failures:// var m int = min(5, 7.1, someNum) // internal compiler error: assertion failedvarmint=max(7.1, 10, someNum) // internal compiler error: assertion failedfmt.Printf("%v %T\n", m, m)
}
The compiler recognising that e.g. min(5, 7.1, someNum) is equivalent to min(5, someNum) and successfully compiling or some form of truncated to int error because this is not code you'd expect to actually see.
What did you see instead?
The internal compiler error.
The text was updated successfully, but these errors were encountered:
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
1.21 feature, so only on release candidate.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
When assigning to an int using
min
/max
and number literals alone, it's possible to determine thatmax(7.1, 10)
is always assignable to int at compile time, and thatmax(5, 7.1)
is not. This is what the compiler indeed seems to do.So I experimented mixing that in various combinations with an int var, as below:
( https://go.dev/play/p/4iSQEEboZFq?v=gotip )
What did you expect to see?
The compiler recognising that e.g.
min(5, 7.1, someNum)
is equivalent tomin(5, someNum)
and successfully compiling or some form oftruncated to int
error because this is not code you'd expect to actually see.What did you see instead?
The internal compiler error.
The text was updated successfully, but these errors were encountered: