Skip to content

x/tools/go/analysis/passes/modernize: RangeIntAnalyzer fix breaks code if type of limit expression is type parameter constrained by multiple integer types #78571

@mwriter

Description

@mwriter

Sample code:

type Integer interface {
    ~int | ~uint
}

func Loop[I Integer](n I) {
    var i I
    for i = 0; i < n; i++ {    // for loop can be modernized using range over int
        println(i)
    }
}

Change the code according to the suggestion and of course get a real error:

func Loop[I Integer](n I) {
    var i I
    for i = range n {    // cannot range over n (variable of type I constrained by Integer): int and uint have different underlying types
        println(i)
    }
}

Metadata

Metadata

Assignees

Labels

BugReportIssues describing a possible bug in the Go implementation.RefactoringIssues related to refactoring toolsToolsThis label describes issues relating to any tools in the x/tools repository.

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions