Skip to content

Commit dabc272

Browse files
ike709ike709
andauthored
RuntimeSearchOperator pragma lint (#2076)
Co-authored-by: ike709 <[email protected]>
1 parent 7fe3aba commit dabc272

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// COMPILE ERROR OD3300
2+
#pragma RuntimeSearchOperator error
3+
/datum/proc/foo()
4+
return
5+
6+
/proc/RunTest()
7+
var/datum/D = new
8+
D:foo()

DMCompiler/Compiler/CompilerError.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public enum WarningCode {
7272
SuspiciousSwitchCase = 3201, // "else if" cases are actually valid DM, they just spontaneously end the switch context and begin an if-else ladder within the else case of the switch
7373
AssignmentInConditional = 3202,
7474
PickWeightedSyntax = 3203,
75-
AmbiguousInOrder = 3204
75+
AmbiguousInOrder = 3204,
76+
RuntimeSearchOperator = 3300,
7677

7778
// 4000 - 4999 are reserved for runtime configuration. (TODO: Runtime doesn't know about configs yet!)
7879
}

DMCompiler/Compiler/DM/DMParser.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2375,10 +2375,15 @@ private void BracketWhitespace() {
23752375
DMASTDereference.Operation operation;
23762376

23772377
switch (token.Type) {
2378+
case TokenType.DM_Colon:
2379+
DMCompiler.Emit(WarningCode.RuntimeSearchOperator, token.Location, "Runtime search operator ':' should be avoided; prefer typecasting and using '.' instead");
2380+
goto case TokenType.DM_QuestionPeriod;
2381+
case TokenType.DM_QuestionColon:
2382+
DMCompiler.Emit(WarningCode.RuntimeSearchOperator, token.Location, "Runtime search operator '?:' should be avoided; prefer typecasting and using '?.' instead");
2383+
goto case TokenType.DM_QuestionPeriod;
23782384
case TokenType.DM_Period:
23792385
case TokenType.DM_QuestionPeriod:
2380-
case TokenType.DM_Colon:
2381-
case TokenType.DM_QuestionColon: {
2386+
{
23822387
var identifier = Identifier();
23832388

23842389
if (identifier == null) {

DMCompiler/DMStandard/DefaultPragmaConfig.dm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@
5151
#pragma AssignmentInConditional warning
5252
#pragma PickWeightedSyntax disabled
5353
#pragma AmbiguousInOrder warning
54+
#pragma RuntimeSearchOperator disabled

0 commit comments

Comments
 (0)