Skip to content

Commit

Permalink
Add new optional lint for weighted pick() syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Absolucy committed Jun 2, 2024
1 parent 916f365 commit a5dca32
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions DMCompiler/Compiler/CompilerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public enum WarningCode {
UnsafeClientAccess = 3200,
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
AssignmentInConditional = 3202,
PickWeightedSyntax = 3203,

// 4000 - 4999 are reserved for runtime configuration. (TODO: Runtime doesn't know about configs yet!)
}
Expand Down
2 changes: 2 additions & 0 deletions DMCompiler/DM/Expressions/Builtins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ public override void EmitPushValue(DMObject dmObject, DMProc proc) {
DMCompiler.ForcedWarning(Location, "Weighted pick() with one argument");
}

DMCompiler.Emit(WarningCode.PickWeightedSyntax, Location, "Use of weighted pick() syntax");

foreach (PickValue pickValue in _values) {
DMExpression weight = pickValue.Weight ?? DMExpression.Create(dmObject, proc, new DMASTConstantInteger(Location, 100)); //Default of 100

Expand Down
1 change: 1 addition & 0 deletions DMCompiler/DMStandard/DefaultPragmaConfig.dm
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@
#pragma EmptyProc disabled // NOTE: If you enable this in OD's default pragma config file, it will emit for OD's DMStandard. Put it in your codebase's pragma config file.
#pragma UnsafeClientAccess disabled // NOTE: Only checks for unsafe accesses like "client.foobar" and doesn't consider if the client was already null-checked earlier in the proc
#pragma AssignmentInConditional warning
#pragma PickWeightedSyntax disabled

0 comments on commit a5dca32

Please sign in to comment.