Skip to content

cmd/compile: type checker (types2) and compiler phase (types) don't agree on what are legal shifts #80983

Description

@griesemer

The following code

var s int
var _ = 1 << ((-1 << s) + 1)

is permitted by the type checker (types2), but runs into a lower-level compiler error (playground):

invalid operation: -1 << s + uint(1) (mismatched types int and uint)

The following code

var s int
var _ = 1 << ((-1 << s) + int(1))

is accepted (playground).

This is particularly odd because in the first example, one would expect the right-most one to be typed as int.

This should be addressed after #77117 is resolved. Requiring that the -1 must fit into an int would likely address this.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions