Skip to content

Commit

Permalink
Fix: Interpreter value_to_bool for module, generic module and gener…
Browse files Browse the repository at this point in the history
…ic module metaclass (#12920)
  • Loading branch information
asterite authored Jan 11, 2023
1 parent 3db4bdd commit ef79d41
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
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

0 comments on commit ef79d41

Please sign in to comment.