From 77fab8727a72d4a037050b08be2568de87d1796e Mon Sep 17 00:00:00 2001
From: Ary Borenszweig <aborenszweig@manas.com.ar>
Date: Tue, 5 Aug 2014 20:56:39 -0300
Subject: [PATCH] Make $1 be the same as $~.not_nil![1] and so on for any n > 0

---
 spec/compiler/parser/parser_spec.cr | 4 ++--
 src/compiler/crystal/parser.cr      | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/spec/compiler/parser/parser_spec.cr b/spec/compiler/parser/parser_spec.cr
index 3f0ff66548..4dc0b1818c 100755
--- a/spec/compiler/parser/parser_spec.cr
+++ b/spec/compiler/parser/parser_spec.cr
@@ -613,8 +613,8 @@ describe "Parser" do
 
   it_parses "foo $a", Call.new(nil, "foo", [Global.new("$a")] of ASTNode)
 
-  it_parses "$1", Call.new(Global.new("$~"), "[]", [1.int32] of ASTNode)
-  it_parses "foo $1", Call.new(nil, "foo", [Call.new(Global.new("$~"), "[]", [1.int32] of ASTNode)] of ASTNode)
+  it_parses "$1", Call.new(Call.new(Global.new("$~"), "not_nil!"), "[]", [1.int32] of ASTNode)
+  it_parses "foo $1", Call.new(nil, "foo", [Call.new(Call.new(Global.new("$~"), "not_nil!"), "[]", [1.int32] of ASTNode)] of ASTNode)
   it_parses "foo /a/", Call.new(nil, "foo", [RegexLiteral.new("a")] of ASTNode)
 
   it_parses "foo out x; x", [Call.new(nil, "foo", [Out.new("x".var)] of ASTNode), "x".var]
diff --git a/src/compiler/crystal/parser.cr b/src/compiler/crystal/parser.cr
index 5dbd5d3152..3bc0aa9b08 100644
--- a/src/compiler/crystal/parser.cr
+++ b/src/compiler/crystal/parser.cr
@@ -707,7 +707,7 @@ module Crystal
       when :GLOBAL
         node_and_next_token Global.new(@token.value.to_s)
       when :GLOBAL_MATCH
-        node_and_next_token Call.new(Global.new("$~"), "[]", [NumberLiteral.new(@token.value.to_s, :i32)] of ASTNode)
+        node_and_next_token Call.new(Call.new(Global.new("$~"), "not_nil!"), "[]", [NumberLiteral.new(@token.value.to_s, :i32)] of ASTNode)
       when :IDENT
         case @token.value
         when :begin
-- 
GitLab