x/tools/internal/refactor/inline: some implicit conversions are undetectable using go/types #63193
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Tools
This label describes issues relating to any tools in the x/tools repository.
Milestone
Consider
func f(x int16) { y := x; _ = (*int16)(&y) }
. If inlining a callf(1)
results in parameter substitution then the output is something like{ y := 1; _ = (*int16)(&y) }
, which doesn't compile because the type of y has changed from int16 to int.The inliner already has a check in place so that nontrivial implicit conversions prevent substitution, but the check does not fire in this case because, according to the type checker, the type of the constant 1 in
f(1)
isint16
, not untyped int. (I'm pretty sure I requested this helpful feature years ago, sigh.) Once the program has been transformed, the statementy := 1
has forgotten all aboutint16
.Unfortunately I think we will need an additional analysis of the argument expression to ascertain whether its type is a purely "bottom-up" property of the syntax or depends on a "top-down" property of the context. If CheckExpr were less inflexible we might be able to invoke it on the argument expression (effectively, with no context) to see what type it gives.
@griesemer @findleyr
The text was updated successfully, but these errors were encountered: