Skip to content

x/tools/internal/refactor/inline: some implicit conversions are undetectable using go/types #63193

@adonovan

Description

@adonovan

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.

@griesemer @findleyr

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.ToolsThis label describes issues relating to any tools in the x/tools repository.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions