From 8fca14f5f87c4e62d0a652b908544ad922c4474f Mon Sep 17 00:00:00 2001 From: Quinton Miller Date: Thu, 2 Nov 2023 00:19:55 +0800 Subject: [PATCH] Fix location of global paths in certain constructs --- spec/compiler/parser/parser_spec.cr | 12 ++++++++++++ src/compiler/crystal/syntax/parser.cr | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr index 28f273be147c..2cfc1ff5042f 100644 --- a/spec/compiler/parser/parser_spec.cr +++ b/spec/compiler/parser/parser_spec.cr @@ -2736,5 +2736,17 @@ module Crystal node = Parser.parse(source).as(EnumDef).members.first node_source(source, node).should eq("protected macro foo; end") end + + it "sets correct location of global path in class def" do + source = "class ::Foo; end" + node = Parser.parse(source).as(ClassDef).name + node_source(source, node).should eq("::Foo") + end + + it "sets correct location of global path in annotation" do + source = "@[::Foo]" + node = Parser.parse(source).as(Annotation).path + node_source(source, node).should eq("::Foo") + end end end diff --git a/src/compiler/crystal/syntax/parser.cr b/src/compiler/crystal/syntax/parser.cr index f891fe640824..e65c7a981b3b 100644 --- a/src/compiler/crystal/syntax/parser.cr +++ b/src/compiler/crystal/syntax/parser.cr @@ -5101,7 +5101,7 @@ module Crystal global = true end - path = parse_path(global, @token.location) + path = parse_path(global, location) skip_space path end