mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 13:40:11 +03:00
Fix Issue 24088 - Nested functions using the shortened syntax were not recognized correctly as declarations.
The fix was simply to amend `isDeclarator` to look for TOK.goesTo (i.e. `=>`)
This commit is contained in:
parent
e21a86f715
commit
e3eccfe9a5
2 changed files with 23 additions and 1 deletions
|
@ -7562,7 +7562,7 @@ LagainStc:
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Valid tokens that follow a declaration
|
// Valid tokens that follow the start of a declaration
|
||||||
case TOK.rightParenthesis:
|
case TOK.rightParenthesis:
|
||||||
case TOK.rightBracket:
|
case TOK.rightBracket:
|
||||||
case TOK.assign:
|
case TOK.assign:
|
||||||
|
@ -7581,6 +7581,23 @@ LagainStc:
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
// To recognize the shortened function declaration syntax
|
||||||
|
case TOK.goesTo:
|
||||||
|
/*
|
||||||
|
1. https://issues.dlang.org/show_bug.cgi?id=24088
|
||||||
|
|
||||||
|
2. We need to make sure the would-be
|
||||||
|
declarator has an identifier otherwise function literals
|
||||||
|
are handled incorrectly. Some special treatment is required
|
||||||
|
here, it turns out that a lot of code in the compiler relies
|
||||||
|
on this mess (in the parser), i.e. having isDeclarator be more
|
||||||
|
precise the parsing of other things go kaboom, so we do it in a
|
||||||
|
separate case.
|
||||||
|
*/
|
||||||
|
if (*haveId)
|
||||||
|
goto case TOK.do_;
|
||||||
|
goto default;
|
||||||
|
|
||||||
case TOK.identifier:
|
case TOK.identifier:
|
||||||
if (t.ident == Id._body)
|
if (t.ident == Id._body)
|
||||||
{
|
{
|
||||||
|
|
|
@ -27,7 +27,12 @@ string test() => "hello"; // works at any scope
|
||||||
static assert(test() == "hello"); // works normally
|
static assert(test() == "hello"); // works normally
|
||||||
static assert(is(typeof(&test) == string function())); // same normal type
|
static assert(is(typeof(&test) == string function())); // same normal type
|
||||||
|
|
||||||
|
struct S(T) {}
|
||||||
|
|
||||||
void func() {
|
void func() {
|
||||||
int a;
|
int a;
|
||||||
int nested() => a; // and at nested scopes too
|
int nested() => a; // and at nested scopes too
|
||||||
|
|
||||||
|
// Issue 24088 - https://issues.dlang.org/show_bug.cgi?id=24088
|
||||||
|
S!int f() => S!int();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue