Skip to content

Commit

Permalink
Adding location to the Path returned by the literal expander for regex (
Browse files Browse the repository at this point in the history
  • Loading branch information
beta-ziliani committed Oct 19, 2021
1 parent 9f90efe commit d702e12
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
17 changes: 17 additions & 0 deletions spec/compiler/codegen/regex_literal_spec.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require "../../spec_helper"

describe "Code gen: regex literal spec" do
it "works in a class variable (#10951)" do
run(%(
require "prelude"
class Foo
@@regex = /whatever/
def self.check_regex
@@regex == /whatever/
end
end
Foo.check_regex
)).to_b.should eq(true)
end
end
4 changes: 3 additions & 1 deletion src/compiler/crystal/semantic/literal_expander.cr
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,11 @@ module Crystal
const = Const.new(@program, @program, const_name, const_value)

@program.types[const_name] = const
else
const = @program.types[const_name].as(Const)
end

Path.new(const_name)
Path.new(const_name).at(const.value)
else
regex_new_call(node, node_value)
end
Expand Down

0 comments on commit d702e12

Please sign in to comment.