-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
Consider func f(x int16) { y := x; _ = (*int16)(&y) }
. If inlining a call f(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)
is int16
, not untyped int. (I'm pretty sure I requested this helpful feature years ago, sigh.) Once the program has been transformed, the statement y := 1
has forgotten all about int16
.
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.