mirror of
https://github.com/dlang/dmd.git
synced 2025-04-27 05:30:13 +03:00
Add supplemental error for @system
variable access (#15464)
This commit is contained in:
parent
04f46ff87d
commit
825e750b93
8 changed files with 41 additions and 15 deletions
|
@ -1167,10 +1167,11 @@ extern (C++) class VarDeclaration : Declaration
|
||||||
bool inClosure; /// is inserted into a GC allocated closure
|
bool inClosure; /// is inserted into a GC allocated closure
|
||||||
bool inAlignSection; /// is inserted into an aligned section on stack
|
bool inAlignSection; /// is inserted into an aligned section on stack
|
||||||
}
|
}
|
||||||
|
bool systemInferred; /// @system was inferred from initializer
|
||||||
}
|
}
|
||||||
|
|
||||||
import dmd.common.bitfields : generateBitFields;
|
import dmd.common.bitfields : generateBitFields;
|
||||||
mixin(generateBitFields!(BitFields, ushort));
|
mixin(generateBitFields!(BitFields, uint));
|
||||||
|
|
||||||
byte canassign; // it can be assigned to
|
byte canassign; // it can be assigned to
|
||||||
ubyte isdataseg; // private data for isDataseg 0 unset, 1 true, 2 false
|
ubyte isdataseg; // private data for isDataseg 0 unset, 1 true, 2 false
|
||||||
|
|
|
@ -244,7 +244,7 @@ public:
|
||||||
// The index of this variable on the CTFE stack, ~0u if not allocated
|
// The index of this variable on the CTFE stack, ~0u if not allocated
|
||||||
unsigned ctfeAdrOnStack;
|
unsigned ctfeAdrOnStack;
|
||||||
private:
|
private:
|
||||||
uint16_t bitFields;
|
uint32_t bitFields;
|
||||||
public:
|
public:
|
||||||
int8_t canassign; // // it can be assigned to
|
int8_t canassign; // // it can be assigned to
|
||||||
uint8_t isdataseg; // private data for isDataseg
|
uint8_t isdataseg; // private data for isDataseg
|
||||||
|
@ -278,6 +278,8 @@ public:
|
||||||
bool inAlignSection() const; // is inserted into aligned section on stack
|
bool inAlignSection() const; // is inserted into aligned section on stack
|
||||||
bool inAlignSection(bool v);
|
bool inAlignSection(bool v);
|
||||||
#endif
|
#endif
|
||||||
|
bool systemInferred() const;
|
||||||
|
bool systemInferred(bool v);
|
||||||
static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
|
static VarDeclaration *create(const Loc &loc, Type *t, Identifier *id, Initializer *init, StorageClass storage_class = STCundefined);
|
||||||
VarDeclaration *syntaxCopy(Dsymbol *) override;
|
VarDeclaration *syntaxCopy(Dsymbol *) override;
|
||||||
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
|
void setFieldOffset(AggregateDeclaration *ad, FieldState& fieldState, bool isunion) override final;
|
||||||
|
|
|
@ -1485,6 +1485,7 @@ extern (C++) abstract class Expression : ASTNode
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
sc.varDecl.storage_class |= STC.system;
|
sc.varDecl.storage_class |= STC.system;
|
||||||
|
sc.varDecl.systemInferred = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -875,6 +875,13 @@ Lagain:
|
||||||
if (sc.setUnsafePreview(global.params.systemVariables, false, loc,
|
if (sc.setUnsafePreview(global.params.systemVariables, false, loc,
|
||||||
"cannot access `@system` variable `%s` in @safe code", sd))
|
"cannot access `@system` variable `%s` in @safe code", sd))
|
||||||
{
|
{
|
||||||
|
if (auto v = sd.isVarDeclaration())
|
||||||
|
{
|
||||||
|
if (v.systemInferred)
|
||||||
|
errorSupplemental(v.loc, "`%s` is inferred to be `@system` from its initializer here", v.toChars());
|
||||||
|
else
|
||||||
|
errorSupplemental(v.loc, "`%s` is declared here", v.toChars());
|
||||||
|
}
|
||||||
return ErrorExp.get();
|
return ErrorExp.get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6090,8 +6090,10 @@ public:
|
||||||
bool inClosure(bool v);
|
bool inClosure(bool v);
|
||||||
bool inAlignSection() const;
|
bool inAlignSection() const;
|
||||||
bool inAlignSection(bool v);
|
bool inAlignSection(bool v);
|
||||||
|
bool systemInferred() const;
|
||||||
|
bool systemInferred(bool v);
|
||||||
private:
|
private:
|
||||||
uint16_t bitFields;
|
uint32_t bitFields;
|
||||||
public:
|
public:
|
||||||
int8_t canassign;
|
int8_t canassign;
|
||||||
uint8_t isdataseg;
|
uint8_t isdataseg;
|
||||||
|
|
|
@ -4561,6 +4561,7 @@ bool setUnsafe(Scope* sc,
|
||||||
else if (!(sc.varDecl.storage_class & STC.trusted))
|
else if (!(sc.varDecl.storage_class & STC.trusted))
|
||||||
{
|
{
|
||||||
sc.varDecl.storage_class |= STC.system;
|
sc.varDecl.storage_class |= STC.system;
|
||||||
|
sc.varDecl.systemInferred = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -2,15 +2,24 @@
|
||||||
REQUIRED_ARGS: -preview=systemVariables
|
REQUIRED_ARGS: -preview=systemVariables
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/systemvariables.d(30): Error: cannot access `@system` variable `gInt` in @safe code
|
fail_compilation/systemvariables.d(39): Error: cannot access `@system` variable `gInt` in @safe code
|
||||||
fail_compilation/systemvariables.d(31): Error: cannot access `@system` variable `gInt` in @safe code
|
fail_compilation/systemvariables.d(29): `gInt` is declared here
|
||||||
fail_compilation/systemvariables.d(32): Error: cannot access `@system` variable `gArr` in @safe code
|
fail_compilation/systemvariables.d(40): Error: cannot access `@system` variable `gInt` in @safe code
|
||||||
fail_compilation/systemvariables.d(33): Error: cannot access `@system` variable `gArr` in @safe code
|
fail_compilation/systemvariables.d(29): `gInt` is declared here
|
||||||
fail_compilation/systemvariables.d(34): Error: cannot access `@system` variable `gInt` in @safe code
|
fail_compilation/systemvariables.d(41): Error: cannot access `@system` variable `gArr` in @safe code
|
||||||
fail_compilation/systemvariables.d(37): Error: cannot access `@system` variable `lSys` in @safe code
|
fail_compilation/systemvariables.d(31): `gArr` is declared here
|
||||||
fail_compilation/systemvariables.d(38): Error: cannot access `@system` variable `lSys` in @safe code
|
fail_compilation/systemvariables.d(42): Error: cannot access `@system` variable `gArr` in @safe code
|
||||||
fail_compilation/systemvariables.d(39): Error: cannot access `@system` variable `lSys` in @safe code
|
fail_compilation/systemvariables.d(31): `gArr` is declared here
|
||||||
fail_compilation/systemvariables.d(41): Error: cannot access `@system` variable `eInt` in @safe code
|
fail_compilation/systemvariables.d(43): Error: cannot access `@system` variable `gInt` in @safe code
|
||||||
|
fail_compilation/systemvariables.d(29): `gInt` is declared here
|
||||||
|
fail_compilation/systemvariables.d(46): Error: cannot access `@system` variable `lSys` in @safe code
|
||||||
|
fail_compilation/systemvariables.d(45): `lSys` is declared here
|
||||||
|
fail_compilation/systemvariables.d(47): Error: cannot access `@system` variable `lSys` in @safe code
|
||||||
|
fail_compilation/systemvariables.d(45): `lSys` is declared here
|
||||||
|
fail_compilation/systemvariables.d(48): Error: cannot access `@system` variable `lSys` in @safe code
|
||||||
|
fail_compilation/systemvariables.d(45): `lSys` is declared here
|
||||||
|
fail_compilation/systemvariables.d(50): Error: cannot access `@system` variable `eInt` in @safe code
|
||||||
|
fail_compilation/systemvariables.d(30): `eInt` is declared here
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
|
@ -2,9 +2,12 @@
|
||||||
REQUIRED_ARGS: -preview=systemVariables
|
REQUIRED_ARGS: -preview=systemVariables
|
||||||
TEST_OUTPUT:
|
TEST_OUTPUT:
|
||||||
---
|
---
|
||||||
fail_compilation/systemvariables_var_init.d(21): Error: cannot access `@system` variable `ptrEnum` in @safe code
|
fail_compilation/systemvariables_var_init.d(24): Error: cannot access `@system` variable `ptrEnum` in @safe code
|
||||||
fail_compilation/systemvariables_var_init.d(22): Error: cannot access `@system` variable `ptrConst` in @safe code
|
fail_compilation/systemvariables_var_init.d(16): `ptrEnum` is inferred to be `@system` from its initializer here
|
||||||
fail_compilation/systemvariables_var_init.d(24): Error: cannot access `@system` variable `ptrVar` in @safe code
|
fail_compilation/systemvariables_var_init.d(25): Error: cannot access `@system` variable `ptrConst` in @safe code
|
||||||
|
fail_compilation/systemvariables_var_init.d(17): `ptrConst` is inferred to be `@system` from its initializer here
|
||||||
|
fail_compilation/systemvariables_var_init.d(27): Error: cannot access `@system` variable `ptrVar` in @safe code
|
||||||
|
fail_compilation/systemvariables_var_init.d(19): `ptrVar` is inferred to be `@system` from its initializer here
|
||||||
---
|
---
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue