Method/function subtyping broken #632

SebastianS90 opened this Issue Apr 21, 2016 · 4 comments


None yet

2 participants

SebastianS90 commented Apr 21, 2016 edited

I don't have an example program yet, but I have some concerns regarding the implementation:
Please have a look at this line in the type checker.

Assume the following scenario:

  • the from type is function(int, bool)->(int)
  • the to type is function(int)->(int)
  • the fromSign is true (from type should be treated as is)
  • the toSign is false (to type should be treated negated)

So the question is whether function(int, bool)->(int) intersects with the negation/complement of function(int)->(int).

In my opinion that is the case. There are functions in the from type. And some of them (I guess all!) are not in the to type. So the answer should be true, but the implementation yields false.

I think the right return statement at that place is: return !fromSign || !toSign;

  • Both types normal -> false
  • Only one negated -> true
  • Both negated -> handled in line 238

Furthermore, I wonder why line 243 differs from 208.

What do you think?


Here we go:

type fun is function(int)->(int)

function foo():
    fun f = &(int x, int y -> y)

And this little friend compiles but throws an ArrayIndexOutOfBoundsException on runtime (probably when accessing the second parameter - that is not given as argument)

type fun is function(int)->(int)

function foo(fun f)->int:
    return f(1)

method main(whiley.lang.System.Console console):
    int z = foo(&(int x, int y -> y))

please have a look at this failed build

WyRT does not compile with my changes in afbb424. Error is:

expected type whiley/io/File:Writer, found {method()->() close,method()->() flush,method(byte[])->() write}

The whiley/io/File:Writer is which is

    method write(byte[]) -> uint,
    method flush(),
    method close(),

The difference is in the write method (return type). Probably you miss an uint return type here.

Is that correct? Does adding it break anything else?


Addition regarding

I added the return type as stated above. All tests succeed. But I guess we don't test the writer at all apart from compiling it as part of wyrt 😆

@SebastianS90 SebastianS90 changed the title from Maybe a bug with method/function subtyping to Method/function subtyping broken Apr 21, 2016
@DavePearce DavePearce closed this Apr 22, 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