Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
41 changes: 41 additions & 0 deletions spec/compiler/semantic/generic_class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1362,4 +1362,45 @@ describe "Semantic: generic class" do
Bar(Int32).new.@foo
CRYSTAL
end

it "doesn't crash on sizeof in inferred ivar type (#14731)" do
assert_error <<-CRYSTAL, "can't infer the type of instance variable '@x' of Bar(T)"
class Foo(N)
end

class Bar(T)
@x = Foo(sizeof(T)).new
end
CRYSTAL
end

it "doesn't crash on offsetof in inferred ivar type (#14731)" do
assert_error <<-CRYSTAL, "can't infer the type of instance variable '@x' of Bar(T)"
class Foo(N)
end

struct SomeStruct
@field : Int32 = 0
end

class Bar(T)
@x = Foo(offsetof(SomeStruct, @field)).new
end
CRYSTAL
end

it "doesn't crash on sizeof in initialize ivar assignment (#14731)" do
assert_error <<-CRYSTAL, "can't infer the type of instance variable '@x' of Bar(Int32)"
class Foo(N)
end

class Bar(T)
def initialize
@x = Foo(sizeof(T)).new
end
end

Bar(Int32).new
CRYSTAL
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ class Crystal::Type
end
next
when SizeOf, InstanceSizeOf, AlignOf, InstanceAlignOf, OffsetOf
next unless @raise
return unless @raise

type_var.raise "can't use #{type_var} as a generic type argument"
end
Expand Down
Loading