ponyc
ponyc copied to clipboard
Capability-matching generic code should not be accepted
trafficstars
his example code is accepted by the compiler, but should not be:
class Worse[T]
new create(out: OutStream, x: (String | T)) =>
match x
| let s: String val => out.print(s)
else
out.print("If x was a String you bet the compiler acted weirdly")
end
actor Main
new create(env: Env) =>
let s1: String ref = String
Worse[String ref](env.out, s1)
s1.append("Ohno")
Currently, this compiles, and results in running the else branch of the match. It should not compile at all, as the accurate dynamic semantics of this would result in a successful match against String (without regards to capabilities) and hence it should be rejected as a capability-only match.