ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.71k stars 415 forks source link

Iftype body is not reified properly, causing failed assertion #1869

Closed plietar closed 7 years ago

plietar commented 7 years ago
class C
    fun c() => None

actor Main
    new create(env: Env) =>
        foo[C box](env, C)

    fun foo[A](env: Env, x: A) =>
        iftype A <: C box then
            x.c()
        end
Building builtin -> /Users/paul/Projects/ponyc/packages/builtin
Building . -> /private/tmp/a
Generating
 Reachability
src/libponyc/reach/reach.c:903: add_type: Assertion `0` failed.

Backtrace:
  0   ponyc                               0x0000000106553e71 ponyint_assert_fail + 161
  1   ponyc                               0x0000000106531714 add_type + 228
  2   ponyc                               0x0000000106530df0 reachable_method + 48
  3   ponyc                               0x0000000106535274 reachable_fun + 276
  4   ponyc                               0x0000000106534eae reachable_call + 110
  5   ponyc                               0x0000000106534511 reachable_expr + 449
  6   ponyc                               0x0000000106534999 reachable_expr + 1609
  7   ponyc                               0x00000001065347cf reachable_expr + 1151
  8   ponyc                               0x0000000106534999 reachable_expr + 1609
  9   ponyc                               0x0000000106531051 handle_stack + 97
  10  ponyc                               0x0000000106530db2 reach + 66
  11  ponyc                               0x00000001064bac29 genexe + 329
  12  ponyc                               0x00000001064aadd2 codegen + 274
  13  ponyc                               0x000000010650f0f3 generate_passes + 51
  14  ponyc                               0x00000001064767e1 compile_package + 161
  15  ponyc                               0x000000010647659f main + 1103
  16  libdyld.dylib                       0x00007fffb0e04255 start + 1
  17  ???                                 0x0000000000000001 0x0 + 1

Printing the type at the assertion shows it is still a type variable, making me think the body isn't getting reified properly.

(lldb) call ast_print(type)
(typeparamref (id A) box x)
Praetonus commented 7 years ago

This occurs when the subtype in an iftype condition is an unconstrained type parameter. The problem is that the reification check in type/reify.c lines 23 to 32 doesn't account for that case.