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

ICE: typeof has no type #7441

Closed
Sija opened this issue Feb 16, 2019 · 2 comments
Closed

ICE: typeof has no type #7441

Sija opened this issue Feb 16, 2019 · 2 comments

Comments

@Sija
Copy link
Contributor

Sija commented Feb 16, 2019

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

@konovod
Copy link
Contributor

konovod commented Feb 16, 2019

even simpler -

v = 1
case v
when Int32
else
  v.as(typeof(v))
end

@asterite
Copy link
Member

Reduced:

a = 1
if a.is_a?(Char)
  1.as(typeof(a))
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants