Skip to content

variable included from file not defined in Main in 1.12 #58511

@pjaap

Description

@pjaap

Hey there, I have a failing test with Julia 1.12 (beta3). Here is a MWE:

A file test.jl constains only the line a = 42.

julia> function foo()
           include("test.jl")
           return a
       end
foo (generic function with 1 method)

With julia 1.11.5:

julia> using Test; @test foo() == 42
Test Passed

With Julia 1.12 (beta3):

julia> using Test; @test foo() == 42
Error During Test at REPL[2]:1
  Test threw exception
  Expression: foo() == 42
  UndefVarError: `a` not defined in `Main`
  Suggestion: check for spelling errors or missing imports.
  Stacktrace:
   [1] foo()
     @ Main ./REPL[1]:3
   [2] top-level scope
     @ REPL[2]:1
   [3] macro expansion
     @ ~/.julia/juliaup/julia-1.12.0-beta3+0.x64.linux.gnu/share/julia/stdlib/v1.12/Test/src/Test.jl:676 [inlined]
ERROR: There was an error during testing

According to the docs, include should evaluate the contents of test.jl in the current module, which is Main. So I believe this is a regression in Julia 1.12

Metadata

Metadata

Assignees

Labels

error messagesBetter, more actionable error messagesneeds decisionA decision on this change is neededtriageThis should be discussed on a triage call

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions