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

Compiler Bug when class constant is Regex that references class member of same name #7865

Closed
jfharrigan opened this issue Jun 6, 2019 · 2 comments · Fixed by #14445
Closed
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen topic:compiler:parser

Comments

@jfharrigan
Copy link

The compiler reports a compiler bug for the following code:

class Pattern
  @@A = "asdf"
  A = /#{@@A}/
end
puts Pattern::A

I can only trigger this bug if the constant and member have the same name.

crystal build test.cr

Module validation failed: Function return type does not match operand type of return inst!
  ret %String** @"Pattern::A", !dbg !74
 %Regex** (Exception)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???

crystal -v

Crystal 0.29.0 [fbfe8b62f] (2019-06-05)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
@straight-shoota
Copy link
Member

@@A should not be a valid name for a class variable.

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Jun 6, 2019
@HertzDevil
Copy link
Contributor

The internal error went away since 1.8 due to changes to regex creation, but now running the program crashes because both constants and class variables are initialized or read using the same LLVM functions (~Pattern::A:init in this case). This is the code that lexes instance or class variables (and globals too, which are still allowed in libs):

private def consume_variable(token_type : Token::Kind, start)
if ident_start?(current_char)
while ident_part?(next_char)
# Nothing to do
end
@token.type = token_type
@token.value = string_range_from_pool(start)
else
unknown_token
end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:codegen topic:compiler:parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants