Skip to content

Commit

Permalink
Adds check for local variable in scope operator check
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruzihm committed Feb 23, 2025
1 parent a7661f6 commit 54de75b
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -645,8 +645,13 @@ private DMExpression BuildScopeIdentifier(DMASTScopeIdentifier scopeIdentifier,
// This is the same behaviour as in BYOND, but BYOND simply raises an undefined var error.
// We want to give end users an explanation at least.
if (scopeMode is Normal && ctx.Proc != null)
return BadExpression(WarningCode.BadExpression, identifier.Location,
"Use of \"type::\" and \"parent_type::\" outside of a context is forbidden");
if (ctx.Proc.GetLocalVariable(identifier.Identifier) != null) {
// actually - it's referring to a local variable named "type" or "parent_type"... just do the usual thing
expression = BuildExpression(scopeIdentifier.Expression, inferredPath);

Check warning

Code scanning / InspectCode

Assignment is not used Warning

Value assigned is not used in any execution path
} else {
return BadExpression(WarningCode.BadExpression, identifier.Location,
"Use of \"type::\" and \"parent_type::\" outside of a context is forbidden");
}

if (identifier.Identifier == "parent_type") {
if (ctx.Type.Parent == null)
Expand Down

0 comments on commit 54de75b

Please sign in to comment.