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

Improves error emission of switch blocks, adds new pragma #1131

Merged
merged 5 commits into from
Dec 20, 2023

Conversation

Altoids1
Copy link
Contributor

Fixes #996.

Summary

Quick and easy audit of our switch parsing, to make use of the new(ish) pragma system.

Changelog

  • Errors in switch parsing are now less likely to cause large code skips in the parser
  • New style pragma added: SuspiciousSwitchCase, for when user codebases use else if as a switch case (which is valid but is read as an 'else' case block with an if block inside it)
  • DMParser calling base.Error() is now marked as obsolete. All calls of that nature should be rewritten to make use of the pragma system and not necessitate throwing, whenever possible (to minimize code skips).

@github-actions
Copy link

github-actions bot commented May 3, 2023

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@Altoids1 Altoids1 force-pushed the better-switch-errors branch 2 times, most recently from 7e4792b to d4ac056 Compare August 7, 2023 04:07
Turns out, BYOND actually is OK with "else if" appearing in a switch block, but takes it to mean an 'else' of the switch, followed by an if-elseif-else ladder within that case block.

Beestation apparently uses this in production, but it's a very odd and ambiguous style (Ike told me he had to fix a bug caused by this recently in Para) so I've made a style warning for it.

This patch also includes some auditing of DMParser Error() emissions so that switch case parsing throws exceptions less often (which reduces code skipping).

I do not love how git submodules work

edit: was missing one comma
DMParser should be emitting actual error codes and avoiding throwing when possible (so as to minimize code-skipping).
@Altoids1 Altoids1 force-pushed the better-switch-errors branch from d4ac056 to e3a78a2 Compare August 7, 2023 04:11
@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

# Conflicts:
#	DMCompiler/DMStandard/DefaultPragmaConfig.dm
#	OpenDreamShared/Compiler/CompilerError.cs
@wixoaGit wixoaGit enabled auto-merge (squash) December 20, 2023 21:32
@wixoaGit wixoaGit merged commit 99db639 into OpenDreamProject:master Dec 20, 2023
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

else if() Switch Case Detection Causes Code Skips
2 participants