Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Interpreter value_to_bool for module, generic module and generic module metaclass #12920

Merged
merged 2 commits into from
Jan 11, 2023
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
40 changes: 40 additions & 0 deletions spec/compiler/interpreter/primitives_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -812,5 +812,45 @@ describe Crystal::Repl::Interpreter do
!a
CRYSTAL
end

it "interprets not for module (#12918)" do
interpret(<<-CRYSTAL).should eq(false)
module MyModule; end

class One
include MyModule
end

!One.new.as(MyModule)
CRYSTAL
end

it "interprets not for generic module" do
interpret(<<-CRYSTAL).should eq(false)
module MyModule(T); end

class One
include MyModule(Int32)
end

!One.new.as(MyModule(Int32))
CRYSTAL
end

it "interprets not for generic module metaclass" do
interpret(<<-CRYSTAL).should eq(false)
module MyModule(T); end

!MyModule(Int32)
CRYSTAL
end

it "interprets not for generic class instance metaclass" do
interpret(<<-CRYSTAL).should eq(false)
class MyClass(T); end

!MyClass(Int32)
CRYSTAL
end
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/interpreter/to_bool.cr
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Crystal::Repl::Compiler
union_to_bool aligned_sizeof_type(type), node: nil
end

private def value_to_bool(node : ASTNode, type : NonGenericClassType | GenericClassInstanceType | VirtualType | MetaclassType | VirtualMetaclassType | ReferenceUnionType | IntegerType | CharType | SymbolType | FloatType | EnumType)
private def value_to_bool(node : ASTNode, type : NonGenericClassType | GenericClassInstanceType | VirtualType | MetaclassType | VirtualMetaclassType | ReferenceUnionType | IntegerType | CharType | SymbolType | FloatType | EnumType | NonGenericModuleType | GenericModuleInstanceType | GenericModuleInstanceMetaclassType | GenericClassInstanceMetaclassType)
pop aligned_sizeof_type(type), node: nil
put_true node: nil
end
Expand Down