erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

Record: Allow mix of shorthand/normal member definition? #238

Closed ytoml closed 1 year ago

ytoml commented 1 year ago

Currently, we cannot define record in shorthand/normal mixed style like:

x = 1
t = {x; y = 10; z = 100} # Syntax Error

How about allow this? If it is acceptable, I will work on it.

mtshiba commented 1 year ago

Yes, this is grammatically allowed. This is a bug in the parser. The reason this is currently an error is the parser only looks at the first element of a brace container ({...} style container) to determine the difference between Record, Dict, and Set.

https://github.com/erg-lang/erg/blob/934be6386dcf7cafe6a383457f00ea23cddc31f4/compiler/erg_parser/parse.rs#L1798-L1833

If this is modified to consider the consistency with all elements and judge it, it will work fine.