Improve parser errors for statements at global scope (#20871)

This commit is contained in:
Dennis 2025-02-15 23:50:34 +01:00 committed by GitHub
parent e85bc5f16e
commit 4b57724c91
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 75 additions and 19 deletions

View file

@ -0,0 +1,26 @@
/**
TEST_OUTPUT:
---
fail_compilation/code_global_scope.d(18): Error: `switch` statement must be inside function scope
fail_compilation/code_global_scope.d(19): Error: `do` statement must be inside function scope
fail_compilation/code_global_scope.d(20): Error: `foreach` statement must be inside function scope
fail_compilation/code_global_scope.d(21): Error: `while` statement must be inside function scope
fail_compilation/code_global_scope.d(22): Error: `if` statement must be inside function scope
fail_compilation/code_global_scope.d(23): Error: `return` statement must be inside function scope
fail_compilation/code_global_scope.d(24): Error: `goto` statement must be inside function scope
fail_compilation/code_global_scope.d(25): Error: `continue` statement must be inside function scope
fail_compilation/code_global_scope.d(26): Error: `break` statement must be inside function scope
---
*/
switch s;
do d;
foreach (i; 0 .. 4) {}
while (x) {}
if (y) {}
return 0;
goto A;
continue B;
break;