Skip to content

Assignment to _ sets the binding type of _ #57497

Open
@xal-0

Description

@xal-0

A syntax.jl test documents:

# `const` assignment to `_` drops the assignment effect,
# and the conversion, but not the rhs.
julia> _::Int = 1
1

julia> _::String = "a"
ERROR: cannot set type for global Main._. It already has a value or is already set to a different type.
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1

On both 1.11 and nightly, a set_binding_type!or globaldecl, respectively, sneaks through.

1.11:

julia> Meta.@lower _::Int = 1
:($(Expr(:thunk, CodeInfo(
    @ none within `top-level scope`
1 ─      global Main._
│   %2 = Int
│        Core.set_binding_type!(Main, :_, %2)
└──      return 1
))))

Nightly:

julia> Meta.@lower _::Int = 1
:($(Expr(:thunk, CodeInfo(
1 ─ %1 = Main.Int
│        $(Expr(:globaldecl, :(Main._), :(%1)))
│        $(Expr(:latestworld))
└──      return 1
))))

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviorcompiler:loweringSyntax lowering (compiler front end, 2nd stage)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions