Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4971,6 +4971,25 @@ describe "Semantic: instance var" do
CRYSTAL
end

it "resolves unqualified constants in block inside instance var initializer (#14827)" do
assert_type(<<-CRYSTAL) { bool }
def with_block
yield
end

module A
struct B
end

struct C
@data : B = with_block { B.new }
end
end

A::C.new.is_a?(A::C)
CRYSTAL
end

it "errors when assigning instance variable at top level block" do
assert_error <<-CRYSTAL, "can't use instance variables at the top level"
def foo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class Crystal::InstanceVarsInitializerVisitor < Crystal::SemanticVisitor

ivar_visitor = MainVisitor.new(program, meta_vars: i.meta_vars)
ivar_visitor.scope = scope.metaclass
value.accept ivar_visitor
ivar_visitor.pushing_type(scope.as(ModuleType)) do
value.accept ivar_visitor
end
end
end
end
Loading