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

Calculating variables in square brackets causes panic #73

Closed GreasySlug closed 2 years ago

GreasySlug commented 2 years ago

Python 3.10.6

>>> [1/2, "a"+"b"]
[0.5, 'ab']

erg 0.2.6

>>> [1.0/2.0, "a"+"b"] 
thread 'main' panicked at 'not yet implemented: [`/`: ({%v12: Float | %v12 == 1.0}, {%v13: Float | %v13 == 2.0}, ) -> Float:
    RatioLit 1.0
    RatioLit 2.0
`+`: ({%v18: Str | %v18 == "a"}, {%v19: Str | %v19 == "b"}, ) -> Str:
    StrLit "a"
    StrLit "b"]', compiler\erg_compiler\effectcheck.rs:66:26
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Traceback (most recent call last):
  File "<string>", line 17, in <module>
ConnectionAbortedError: [WinError 10053] 確立された接続がホスト コンピューターのソウトウェアによって中止されました。
error: process didn't exit successfully: `target\debug\erg.exe` (exit code: 101)

Is this intended?

mtshiba commented 2 years ago

This is probably because you put objects of different types into the array.

https://github.com/erg-lang/erg/blob/main/doc/EN/syntax/10_array.md

As written here, it is prohibited by default. Must be typed explicitly.

That said, this is an unintended behavior.

It should report errors normally and give hints to specify type.

mtshiba commented 2 years ago

Fixed in https://github.com/erg-lang/erg/commit/0ebb0ce94c8e547babae7387e11419a76f32b9cd.