Method/function intersection (still) broken #636

Closed
SebastianS90 opened this Issue Apr 24, 2016 · 0 comments

Projects

None yet

2 participants

@SebastianS90
Contributor

Follow up from #632.

While normal subtyping of methods is working fine thanks to my fix, intersection is still buggy.
According to the current implementation, two method types intersect if and only if:

  • same number of parameters
  • same number of return values
  • return types intersect
  • complement of parameter types intersect

I agree that it is important to have intersecting return types. A method cannot return int and bool at the same time.
But the last condition is wrong. An intersecting method can easily specify any for each parameter type, then it will be in the set of both types and therefore in their intersection. (I hereby assume that parameter types in all methods must not be void).
The complement of two types intersect almost every time, except if both types are any. So the current implementation does not think that type method(any)->() intersects with itself.

Consider this program:

type t is method(any)->()
method test(any x):
    !t m = &test

It should not compile because &test is in type t and therefore not a subtype of !t.
But it compiles due to this bug.

@DavePearce DavePearce closed this in #637 Apr 25, 2016
@DavePearce DavePearce modified the milestone: v0.3.40 May 27, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment