Skip to content

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

Open

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

  1. added theissue type on Aug 20, 2026
  2. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Aug 20, 2026
  3. griesemer commented on Aug 20, 2026

    @griesemer
    ContributorAuthor

    Also related: #79252

  4. added this to the Go1.28 milestone on Aug 25, 2026
  5. gopherbot commented on Oct 9, 2026

    @gopherbot
    Contributor

    Change https://go.dev/cl/847765 mentions this issue: go/types, types2: report error for oversized non-constant shift counts

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