go/types: incorrect error message for string(1<<s + 1.1) #21982
Type-checking the program
produces the error:
But the correct error would be:
See also the TODO in go/types/conversions.go.
The text was updated successfully, but these errors were encountered:
Under certain circumstances involving shifts, go/types didn't verify that untyped constant values were representable by the relevant type, leading to the acceptance of incorrect programs (see the issue). Fixing this code exposed another problem with int-to-string conversions which suddenly failed because now the type-checker complained that a (constant) integer argument wasn't representable as a string. Fixed that as well. Added many additional tests covering the various scenarious. Found two cmd/compile bugs in the process (#21979, #21981) and filed a go/types TODO (#21982). Fixes #21727. Change-Id: If443ee0230979cd7d45d2fc669e623648caa70da Reviewed-on: https://go-review.googlesource.com/65370 Reviewed-by: Alan Donovan <firstname.lastname@example.org>
I think the current error is fine.
If we replace the shift expression, we get
Also, we do allow shifting of untyped float constants (e.g.,