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

Berry import strict now detects useless expr without side effects #18997

Merged
merged 1 commit into from
Jun 29, 2023

Conversation

s-hadinger
Copy link
Collaborator

Description:

Berry: new test added when compiling in strict mode import strict. Now the parser detects when statements or expression don't have any side effect, which means that they do nothing. It's most certainly a mistake.

This detects for example self.attr 0 which should have been self.attr = 0, we was silently accepted as two useless expression.

> def f() 1 end
syntax_error: stdin:1: strict: expression without side effect detected

> def f(x) x 0 end
syntax_error: stdin:1: strict: expression without side effect detected

> def f(x) return x end     # this is ok

Checklist:

  • The pull request is done against the latest development branch
  • Only relevant files were touched
  • Only one feature/fix was added per PR and the code change compiles without warnings
  • The code change is tested and works with Tasmota core ESP8266 V.2.7.4.9
  • The code change is tested and works with Tasmota core ESP32 V.2.0.10
  • I accept the CLA.

NOTE: The code change must pass CI tests. Your PR cannot be merged unless tests pass

@s-hadinger s-hadinger merged commit 34456e6 into arendst:development Jun 29, 2023
@sfromis
Copy link
Contributor

sfromis commented Jun 29, 2023

Good improvement :-)

One funny edge case:

var a,b
def f() b:=a end
BRY: Exception> 'syntax_error' - input:1: strict: expression without side effect detected

Not a very intuitive message, when the walrus purpose is to actually have a side effect. Of course, not very useful to use walrus when a simple assignment would be the thing to do, hence I do not really see this as a "bug".

@s-hadinger
Copy link
Collaborator Author

Nah this is a bug. I thought I marked a walrus assignment as a side effect.

@s-hadinger
Copy link
Collaborator Author

Fixed in #18999

RaphDaMan pushed a commit to RaphDaMan/Tasmota that referenced this pull request Sep 10, 2024
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.

2 participants