Skip to content

Commit

Permalink
new test cases, new warning
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruzihm committed Feb 24, 2025
1 parent cef6c73 commit edf0a46
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
10 changes: 5 additions & 5 deletions Content.Tests/DMProject/Tests/Operators/scope.dm
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ var/static/one = "one"
var/static/six = "three four five six"

/datum/six
var/price = 60
better
price = parent_type::price + 40
var/toughness = 100
reinforced
toughness = parent_type::toughness + 50

/proc/return_two()
return "two"
Expand Down Expand Up @@ -66,5 +66,5 @@ var/static/one = "one"
var/datum/three/threetest = new
threetest.typetest()

var/datum/six/better/fourtest = new()
ASSERT(fourtest.price == 100)
var/datum/six/reinforced/fourtest = new()
ASSERT(fourtest.toughness == 150)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// COMPILE ERROR OD0011

/datum/thing
var/price = 60
better
/datum/armor
var/toughness = 100
reinforced
proc/test_proc()
price = parent_type::price + 40
toughness = parent_type::toughness + 50
1 change: 1 addition & 0 deletions DMCompiler/Compiler/CompilerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public enum WarningCode {

// 2000 - 2999 are reserved for compiler configuration of actual behaviour.
SoftReservedKeyword = 2000, // For keywords that SHOULD be reserved, but don't have to be. 'null' and 'defined', for instance
ScopeOperandNamedType = 2001, // Scope operator is used on a var named type or parent_type, maybe unintentionally
DuplicateVariable = 2100,
DuplicateProcDefinition = 2101,
PointlessParentCall = 2205,
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DM/Builders/DMExpressionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ private DMExpression BuildScopeIdentifier(DMASTScopeIdentifier scopeIdentifier,
if (scopeMode is Normal && ctx.Proc != null) {

Check warning

Code scanning / InspectCode

Expression is always true according to nullable reference types' annotations Warning

Expression is always true according to nullable reference types' annotations
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
Compiler.Emit(WarningCode.SoftReservedKeyword, identifier.Location,
Compiler.Emit(WarningCode.ScopeOperandNamedType, identifier.Location,
$"Using scope operator :: on a variable named \"type\" or \"parent_type\" is ambiguous. Consider changing the variable name from \"{identifier.Identifier}\".");
expression = BuildExpression(scopeIdentifier.Expression, inferredPath);
} else {
Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DMStandard/DefaultPragmaConfig.dm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

//2000-2999
#pragma SoftReservedKeyword error
#pragma ScopeOperandNamedType warning
#pragma DuplicateVariable warning
#pragma DuplicateProcDefinition error
#pragma PointlessParentCall warning
Expand Down

0 comments on commit edf0a46

Please sign in to comment.