From edf0a460ce8211ee7514fce7ff81869ee22c96ac Mon Sep 17 00:00:00 2001 From: Richard Van Tassel Date: Sun, 23 Feb 2025 22:57:13 -0500 Subject: [PATCH] new test cases, new warning --- Content.Tests/DMProject/Tests/Operators/scope.dm | 10 +++++----- .../Tests/Operators/scope_parent_type_fails.dm | 8 ++++---- DMCompiler/Compiler/CompilerError.cs | 1 + DMCompiler/DM/Builders/DMExpressionBuilder.cs | 2 +- DMCompiler/DMStandard/DefaultPragmaConfig.dm | 1 + 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Content.Tests/DMProject/Tests/Operators/scope.dm b/Content.Tests/DMProject/Tests/Operators/scope.dm index 5a1dfc928c..5147848801 100644 --- a/Content.Tests/DMProject/Tests/Operators/scope.dm +++ b/Content.Tests/DMProject/Tests/Operators/scope.dm @@ -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" @@ -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) \ No newline at end of file + var/datum/six/reinforced/fourtest = new() + ASSERT(fourtest.toughness == 150) \ No newline at end of file diff --git a/Content.Tests/DMProject/Tests/Operators/scope_parent_type_fails.dm b/Content.Tests/DMProject/Tests/Operators/scope_parent_type_fails.dm index 82564f5fe9..dad6979632 100644 --- a/Content.Tests/DMProject/Tests/Operators/scope_parent_type_fails.dm +++ b/Content.Tests/DMProject/Tests/Operators/scope_parent_type_fails.dm @@ -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 \ No newline at end of file + toughness = parent_type::toughness + 50 \ No newline at end of file diff --git a/DMCompiler/Compiler/CompilerError.cs b/DMCompiler/Compiler/CompilerError.cs index 2209b23747..62f07718cc 100644 --- a/DMCompiler/Compiler/CompilerError.cs +++ b/DMCompiler/Compiler/CompilerError.cs @@ -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, diff --git a/DMCompiler/DM/Builders/DMExpressionBuilder.cs b/DMCompiler/DM/Builders/DMExpressionBuilder.cs index 39af4b1e51..68452219d2 100644 --- a/DMCompiler/DM/Builders/DMExpressionBuilder.cs +++ b/DMCompiler/DM/Builders/DMExpressionBuilder.cs @@ -647,7 +647,7 @@ private DMExpression BuildScopeIdentifier(DMASTScopeIdentifier scopeIdentifier, if (scopeMode is Normal && ctx.Proc != null) { 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 { diff --git a/DMCompiler/DMStandard/DefaultPragmaConfig.dm b/DMCompiler/DMStandard/DefaultPragmaConfig.dm index 125a11f244..15f439f14d 100644 --- a/DMCompiler/DMStandard/DefaultPragmaConfig.dm +++ b/DMCompiler/DMStandard/DefaultPragmaConfig.dm @@ -15,6 +15,7 @@ //2000-2999 #pragma SoftReservedKeyword error +#pragma ScopeOperandNamedType warning #pragma DuplicateVariable warning #pragma DuplicateProcDefinition error #pragma PointlessParentCall warning