forked from ldc-developers/ldc
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix context of some nested aggregates
The context for instances of aggregates *not* nested in the current function, but some parent. Fixes ldc-developers#2960.
- Loading branch information
Showing
2 changed files
with
38 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// RUN: %ldc -run %s | ||
|
||
template listDir(alias handler) | ||
{ | ||
struct NestedStruct | ||
{ | ||
void callHandler() { handler(); } | ||
} | ||
|
||
class NestedClass | ||
{ | ||
void callHandler() { handler(); } | ||
} | ||
|
||
void nestedFunc() { handler(); } | ||
|
||
void listDir() | ||
{ | ||
int a = 123; | ||
void foo() { assert(a == 123); } | ||
|
||
// pass local listDir() frame as context | ||
foo(); | ||
|
||
// pass parent context for sibling symbols: | ||
NestedStruct().callHandler(); | ||
(new NestedClass).callHandler(); | ||
nestedFunc(); | ||
} | ||
} | ||
|
||
void main() | ||
{ | ||
int magic = 0xDEADBEEF; | ||
listDir!(() { assert(magic == 0xDEADBEEF); })(); | ||
} |