Skip to content

x/tools/internal/refactor/inline: replacing a variable by a constant may cause type error #62664

Closed
@adonovan

Description

@adonovan

The inliner replaces parameters by their arguments when possible. If the argument is a constant, then certain expressions that were statically valid (but would panic if evaluated) before are now statically invalid. For example, attempting to slice an empty string:

func _() {
    const s = ""
    f(s)
}
func (s string) { _ = s[:1] } // error: cannot slice empty string

or negating minint:

func _() {
    const x = -0x80000000
    f(x)
}
func f(x int32) { var _ int32 = -x } // error: - -0x80000000 overflows int32

In general I suspect such errors cannot be detected without executing the type checker on the result, which is not something that can be done by the inliner itself. Sigh.

@findleyr @timothy-king

Metadata

Metadata

Assignees

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.RefactoringIssues related to refactoring toolsToolsThis 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