jfecher / ante

A safe, easy systems language
http://antelang.org
MIT License
1.9k stars 79 forks source link

entered unreachable code #137

Closed eldesh closed 2 years ago

eldesh commented 2 years ago

Hi. I found an issue it seems to be a compiler bug. The compiler panicked by entering the following code.

Environment

Code

type Vec = x: float, y: float, z: float
type Triple a = first: a, second: a, third: a
type Sphere = center: Vec, radius: float
type Plane = p: Vec, n: Vec

init : Triple Sphere, Plane =
    ss = Triple (Sphere (Vec -2.0 0.0 -3.5) 0.5)
                (Sphere (Vec -0.5 0.0 -3.0) 0.5)
                (Sphere (Vec  1.0 0.0 -2.2) 0.5)
    plane = Plane (Vec 0.0 -0.5 0.0)
                  (Vec 0.0  1.0 0.0)
    ss, plane

Error

$ ante main.an
thread 'main' panicked at 'internal error: entered unreachable code: Cannot unify a polytype: (forall 128. (Vec - Vec -> Plane can 128))', src/types/typechecker.rs:1185:25
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
jfecher commented 2 years ago

Thank you for the issue, yes this seems to be a bug

jfecher commented 2 years ago

Fixed the immediate issue caused by a parsing error parsing init : Triple Sphere, Plane = as (init: Triple Sphere), Plane =. This lead to trying to reassign the Plane constructor to a new value, hence the error. The error should be made clearer as well, but that is a separate issue.