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

Internal error when using sizeof as generic type argument in inferred ivar type #14731

Open
HertzDevil opened this issue Jun 19, 2024 · 0 comments

Comments

@HertzDevil
Copy link
Contributor

The following is currently a compilation error until #5427 is resolved:

class Foo(N)
end

class Bar(T)
  @x : Foo(sizeof(T)) # Error: can't use sizeof(T) as a generic type argument
end

The following, however, produces an internal IndexError:

class Foo(N)
end

class Bar(T)
  @x = Foo(sizeof(T)).new
end
Index out of bounds (IndexError)
  from src/indexable.cr:89:20 in '[]'
  from src/compiler/crystal/types.cr:1602:11 in 'instantiate'
  from src/compiler/crystal/semantic/type_lookup.cr:296:11 in 'lookup'
  from src/compiler/crystal/semantic/type_lookup.cr:50:5 in 'lookup_type?:self_type:allow_typeof:find_root_generic_type_parameters'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:1168:14 in 'lookup_type?'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:1128:5 in 'lookup_type?'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:644:9 in 'guess_type'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:357:14 in 'process_assign_instance_var'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:321:9 in 'process_assign_instance_var'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:222:11 in 'process_assign'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:205:7 in 'process_assign'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:127:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/semantic/semantic_visitor.cr:110:7 in 'visit'
  from src/compiler/crystal/semantic/type_guess_visitor.cr:1208:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/syntax/ast.cr:184:27 in 'accept_children'
  from src/compiler/crystal/syntax/visitor.cr:28:11 in 'accept'
  from src/compiler/crystal/semantic/hooks.cr:25:7 in 'visit_with_finished_hooks'
  from src/compiler/crystal/semantic/type_declaration_processor.cr:144:5 in 'process'
  from src/compiler/crystal/semantic.cr:77:7 in 'top_level_semantic'
  from src/compiler/crystal/semantic.cr:22:23 in 'semantic:cleanup'
  from src/compiler/crystal/compiler.cr:210:14 in 'compile'
  from src/compiler/crystal/command.cr:359:3 in 'compile'
  from src/compiler/crystal/command.cr:239:5 in 'run_command'
  from src/compiler/crystal/command.cr:112:7 in 'run'
  from src/compiler/crystal/command.cr:55:5 in 'run'
  from src/compiler/crystal/command.cr:54:3 in 'run'
  from src/compiler/crystal.cr:11:1 in '__crystal_main'
  from src/crystal/main.cr:118:5 in 'main_user_code'
  from src/crystal/main.cr:104:7 in 'main'
  from src/crystal/main.cr:130:3 in 'main'

The same happens if @x is assigned inside #initialize instead.

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

1 participant