ponyc icon indicating copy to clipboard operation
ponyc copied to clipboard

Enhancement: Inherit iftype contraints in lambda bodies

Open patroclos opened this issue 6 years ago • 2 comments

I think there is no apparent reason not to do this. Here is a small example of what I mean:

actor Main
  new create(e: Env) => None
  
  fun test[A: (Main box | None)](a: A) =>
    iftype A <: Main then
      let lambda = {(): Main box => a}
    end

And the error I get:

Error:
C:\Users\Joshua\Documents\workspace\lsp-ony\_test\test_pkg\main.pony:6:38: function body isn't the result type
            let x = {(): Main box => a}
                                     ^
    Info:
    C:\Users\Joshua\Documents\workspace\lsp-ony\_test\test_pkg\main.pony:6:26: function return type: Main box
                let x = {(): Main box => a}
                             ^
    C:\Users\Joshua\Documents\workspace\lsp-ony\_test\test_pkg\main.pony:6:38: function body type: this->A #read
                let x = {(): Main box => a}
                                         ^
    C:\Users\Joshua\Documents\workspace\lsp-ony\_test\test_pkg\main.pony:4:29: None val is not a subtype of Main box
        fun test[A: (Main box | None)](a: A) =>
                                ^
    C:\Users\Joshua\Documents\workspace\lsp-ony\_test\test_pkg\main.pony:4:29: not every element of (Main box | None val) is a subtype of Main box
        fun test[A: (Main box | None)](a: A) =>
                                ^

patroclos avatar Mar 18 '19 01:03 patroclos