diff --git a/spec/compiler/codegen/debug_spec.cr b/spec/compiler/codegen/debug_spec.cr index a1f5217d99bf..018a07e8f1b2 100644 --- a/spec/compiler/codegen/debug_spec.cr +++ b/spec/compiler/codegen/debug_spec.cr @@ -321,4 +321,14 @@ describe "Code gen: debug" do end CRYSTAL end + + it "doesn't fail if class var initializer is followed by metaclass (#15970)" do + codegen <<-CRYSTAL, debug: Crystal::Debug::All + module Foo + @@x = 1 + end + + Int32 + CRYSTAL + end end diff --git a/src/compiler/crystal/codegen/codegen.cr b/src/compiler/crystal/codegen/codegen.cr index 1cba5be39a4d..108ebfb083c3 100644 --- a/src/compiler/crystal/codegen/codegen.cr +++ b/src/compiler/crystal/codegen/codegen.cr @@ -964,6 +964,7 @@ module Crystal def visit(node : TypeOf) # convert virtual metaclasses to non-virtual ones, because only the # non-virtual type IDs are needed + set_current_debug_location(node) if @debug.line_numbers? @last = type_id(node.type.devirtualize) false end @@ -1723,6 +1724,7 @@ module Crystal accept replacement else node_type = node.type + set_current_debug_location(node) if @debug.line_numbers? # Special case: if the type is a type tuple we need to create a tuple for it if node_type.is_a?(TupleInstanceType) @last = allocate_tuple(node_type) do |tuple_type, i| @@ -1736,6 +1738,7 @@ module Crystal end def visit(node : Generic) + set_current_debug_location(node) if @debug.line_numbers? @last = type_id(node.type) false end diff --git a/src/compiler/crystal/semantic/new.cr b/src/compiler/crystal/semantic/new.cr index f47fedc146f1..2c7be1856090 100644 --- a/src/compiler/crystal/semantic/new.cr +++ b/src/compiler/crystal/semantic/new.cr @@ -159,7 +159,7 @@ module Crystal arg = Splat.new(arg).at(self) if instance_type.splat_index == i arg end - new_generic = Generic.new(Path.new(instance_type.name), generic_type_args) + new_generic = Generic.new(Path.new(instance_type.name), generic_type_args).at(self) alloc = Call.new(new_generic, "allocate").at(self) else alloc = Call.new("allocate").at(self)