cmd/compile: Compiler Type Inferencing on Methods With Narrowing Types #60975
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, on go tip
What did you do?
There are two scenarios here.
Scenario 1:
https://go.dev/play/p/z_69dFItT4D?v=gotip
Scenario 2:
https://go.dev/play/p/PNQ2bWh3BO-?v=gotip
What did you expect to see?
For scenario 1: A compiler error saying
PrintThing2
cannot be called using variabletwo
because typesThing[int]
andThing[string]
do not match. I can understand how this scenario would be an unsupported edge case because of the complications of having to dynamically filter method bindings upon struct creation, but if methods really are just functions, then I could also see this being a reasonable feature to have implemented. If this feature is allowed, then there is a secondary issue where theinputParam
argument changes type.For scenario 2: This builds off of scenario 1. In this case the compiler throws a rather confusing error saying that an int is not an int. I do not see why the
inputParam
variable would be constrained by any when it is strictly declared as inint
. I would expect to be able to callintAsArg
without issue. Of note is the same error regarding theinputParam
changing its type is present.The text was updated successfully, but these errors were encountered: