flix / flix

The Flix Programming Language
https://flix.dev/
Other
2.08k stars 150 forks source link

Wrong type error? Region escapes when used locally #3801

Closed jaschdoc closed 1 year ago

jaschdoc commented 2 years ago
-- Type Error -------------------------------------------------- Array.flix

>> The region variable 'r1' escapes its scope.

1354 |>     pub def findIndices(f: a -> Bool & ef, a: ScopedArray[a, r]): ScopedArray[Int32, r] \ { ef, Read(r), Write(r) } = region r1 {
1355 |>         let len = length(a);
1356 |>         let l = new MutList(r1);
1357 |>         def loop(i) = {
1358 |>             if (i >= len)
1359 |>                 ()
1360 |>             else {
1361 |>                 if (f(a[i])) MutList.push!(i, l) else ();
1362 |>                 loop(i + 1)
1363 |>             }
1364 |>         };
1365 |>         loop(0);
1366 |>         MutList.toArray(l, Scoped.regionOf(a))
1367 |>     }

region variable escapes.

The escaping expression has type:

  ScopedArray[Int32, r or (?eff795361 and r1)]

which contains the region variable.
magnus-madsen commented 2 years ago

@mlutze I think r gets instantiated with r1 which should not really happen. This suggests that getSubstFromParams might even be necessary for correctness.

mlutze commented 2 years ago

Is this still an issue? I see that Array.findIndices is using scoped arrays without issue on master.

jaschdoc commented 2 years ago

Yes but I'm not sure it's the same implementation. I'll have to check whether the above still produces an error. I'll get back to you on that

magnus-madsen commented 1 year ago

I think this has been fixed.

jaschdoc commented 1 year ago

Oops I forgot to check this

jaschdoc commented 1 year ago

Ok I've tried this on master and it works :+1: