Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds a warning when assigning a value in a conditional #1596

Merged
merged 2 commits into from
Jan 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1065,7 +1065,12 @@ private DMASTProcStatementSet[] ProcSetEnd(bool allowMultiple) {
Consume(TokenType.DM_LeftParenthesis, "Expected '('");
BracketWhitespace();
DMASTExpression? condition = Expression();
if (condition == null) Error("Expected a condition");
if (condition == null) {
Error("Expected a condition");
}
if (condition is DMASTAssign) {
DMCompiler.Emit(WarningCode.AssignmentInConditional, condition.Location, "Assignment in conditional");
}
BracketWhitespace();
ConsumeRightParenthesis();
Whitespace();
Expand Down
2 changes: 1 addition & 1 deletion DMCompiler/DMStandard/DefaultPragmaConfig.dm
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@
#pragma EmptyBlock notice
#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
1 change: 1 addition & 0 deletions OpenDreamShared/Compiler/CompilerError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum WarningCode {
EmptyProc = 3101,
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,

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