Below code:
arr = [{ "foo" => "bar" }]
arr.map do |v|
case v
when Hash
pp :hash
else
pp v.as(typeof(v))
end
end
raises ICE:
BUG: `typeof(v)` at eval:7:13 has no type (Exception)
from Crystal::ASTNode+@Crystal::ASTNode#type:Crystal::Type+
from Crystal::Cast#update<Nil>:(Crystal::Type+ | Nil)
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::If>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#expand<Crystal::Case>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::Block>:(Bool | Nil)
from Crystal::Block@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::Call#match_block_arg<Crystal::Match>:Tuple(Array(Crystal::Var+) | Nil, Crystal::Type+ | Nil)
from Crystal::Call#instantiate<Crystal::Matches, Crystal::Type+, Nil, Bool>:Array(Crystal::Def+)
from Crystal::Call#lookup_matches_in_type<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Nil, String, Bool, Bool, Bool>:Array(Crystal::Def+)
from Crystal::Call#lookup_matches_in:with_literals<Crystal::Type+, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Bool>:Array(Crystal::Def+)
from Crystal::Call#lookup_matches:with_literals<Bool>:Array(Crystal::Def+)
from Crystal::Call#recalculate:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::Call#lookup_matches_in_type<Crystal::Program, Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Nil, String, Bool, Bool, Bool>:Array(Crystal::Def+)
from Crystal::Call#lookup_matches_without_splat<Array(Crystal::Type+), (Array(Crystal::NamedArgumentType) | Nil), Bool>:Array(Crystal::Def+)
from Crystal::Call#lookup_matches:with_literals<Bool>:Array(Crystal::Def+)
from Crystal::Call#recalculate:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::MainVisitor#expand<Crystal::StringInterpolation>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::MainVisitor#visit<Crystal::Call>:Bool
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::MainVisitor>:Nil
from Crystal::Program#visit_main<Crystal::ASTNode+, Crystal::MainVisitor, Bool, Bool>:Crystal::ASTNode+
from Crystal::Program#semantic<Crystal::ASTNode+, Bool>:Crystal::ASTNode+
from Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
from Crystal::Command#run_command<Bool>:Nil
from Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil)
from __crystal_main
from main
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
Might be a duplicate of #5805
even simpler -
v = 1
case v
when Int32
else
v.as(typeof(v))
end
Reduced:
a = 1
if a.is_a?(Char)
1.as(typeof(a))
end