Skip to content

Compiler implicitely imports symbols in module #44604

@Pangoraw

Description

@Pangoraw

Initally reported in fonsp/Pluto.jl#1973. When executing a simple block with a for loop in the REPL, the compiler will use isdefined(Main,s) which will have a side effect of implicitely importing the variable in Main and making impossible to assign to it in the given expression.

julia> begin
           first = 1
           for _ in false
               first
           end
       end
ERROR: cannot assign a value to variable Base.first from module Main
Stacktrace:
 [1] top-level scope
   @ ./REPL[1]:2

This is where I suspect the compiler uses isdefined(Main, :first) and isconst(Main, :first) for this given expression (from a gdb stacktrace):

if isdefined(M,s)
if isconst(M,s)

The issue is that isdefined(m, s) will resolve the binding and implicitely import it inside m as a side effect. The same is also true for isconst(m, s). Maybe their usage should not have this side-effect in this particular case ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions