enso-org / enso

Hybrid visual and textual functional programming.
https://enso.org
Apache License 2.0
7.34k stars 323 forks source link

Operator-block syntax pitfall #11203

Open jdunkerley opened 2 days ago

jdunkerley commented 2 days ago
from Standard.Base import all

main =
    test = [1] + [2] + [3] + [4]
    test.to_text

results in [1,2,3,4]

however

from Standard.Base import all

main =
    test = [1] +
        [2] +
        [3] +
        [4]
    test.to_text

results in [1, 4]

kazcw commented 2 days ago

This is the same syntactic pitfall as here: #9944 We could improve this by emitting a warning when an expression with no side effects is evaluated without being used. That might be a tall order for the backend to implement in general, but this is not the first time a bug has been reported due to this pitfall--to catch this specific case, we could have a warning if an operator-section occurs in statement context. This would be a syntax warning, so the parser would be the place to implement it.