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
10 changes: 10 additions & 0 deletions spec/compiler/codegen/debug_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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|
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/new.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down