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

Use separate names for constant and class variable internals #14445

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/compiler/codegen/class_var_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,19 @@ describe "Codegen: class var" do
mod.to_s.should_not contain("x:init")
end

it "doesn't error if class var shares name with const (#7865)" do
run(<<-CRYSTAL).to_string.should eq("asdfgh")
require "prelude"

class Pattern
@@A = "asdf"
A = "\#{@@A}gh"
end

Pattern::A
CRYSTAL
end

it "catch infinite loop in class var initializer" do
run(%(
require "prelude"
Expand Down
2 changes: 1 addition & 1 deletion spec/llvm-ir/const-read-debug-loc.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def a_foo
end

THE_FOO.foo
# CHECK: call %Foo** @"~THE_FOO:read"()
# CHECK: call %Foo** @"~THE_FOO:const_read"()
# CHECK-SAME: !dbg [[LOC:![0-9]+]]
# CHECK: [[LOC]] = !DILocation
# CHECK-SAME: line: 12
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/const.cr
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ class Crystal::CodeGenVisitor
return global
end

read_function_name = "~#{const.llvm_name}:read"
read_function_name = "~#{const.llvm_name}:const_read"
func = typed_fun?(@main_mod, read_function_name) || create_read_const_function(read_function_name, const)
func = check_main_fun read_function_name, func
call func
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/types.cr
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ module Crystal
property? no_init_flag = false

def initialized_llvm_name
"#{llvm_name}:init"
"#{llvm_name}:const_init"
end

# Returns `true` if this constant's value is a simple literal, like
Expand Down
Loading