From 73aa7e4df5775dce521615a0da5c09e1735a3cd2 Mon Sep 17 00:00:00 2001 From: Simeon Schaub Date: Sat, 3 Apr 2021 04:43:39 +0200 Subject: [PATCH] fix macro hygiene for `@nospecialize(::T)` (#40293) --- src/macroexpand.scm | 3 ++- test/syntax.jl | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/macroexpand.scm b/src/macroexpand.scm index a0f05a3af687a..5e55c7bbb29c1 100644 --- a/src/macroexpand.scm +++ b/src/macroexpand.scm @@ -210,7 +210,8 @@ ((atom? v) '()) (else (case (car v) - ((... kw |::| =) (try-arg-name (cadr v))) + ((|::|) (if (length= v 2) '() (try-arg-name (cadr v)))) + ((... kw =) (try-arg-name (cadr v))) ((escape) (list v)) ((hygienic-scope) (try-arg-name (cadr v))) ((meta) ;; allow certain per-argument annotations diff --git a/test/syntax.jl b/test/syntax.jl index aeaefdcbc832e..eb49a9dfddd60 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2771,3 +2771,9 @@ end @test eval(Expr(:string, "a", Expr(:string, "b", "c"))) == "abc" @test eval(Expr(:string, "a", Expr(:string, "b", Expr(:string, "c")))) == "abc" + +macro m_nospecialize_unnamed_hygiene() + return :(f(@nospecialize(::Any)) = Any) +end + +@test @m_nospecialize_unnamed_hygiene()(1) === Any