Is C# type system sound and decidable? -
i know java's type system unsound (it fails type check constructs semantically legal) , undecidable (it fails type check construct).
for instance, if copy/paste following snippet in class , compile it, compiler crash stackoverflowexception
(how apt). undecidability.
static class listx<t> {} static class c<p> extends listx<listx<? super c<c<p>>>> {} listx<? super c<byte>> crash = new c<byte>();
java uses wildcards type bounds, form of use-site variance. c# on other hand, uses declaration site variance annotation (with in
, out
keywords). known declaration-site variance weaker use-site variance (use-site variance can express declaration-site variance can, , more -- on down side, it's more verbose).
so question is: c# type system sound , decidable? if not, why?
is c# type system sound , decidable?
it depends on restrictions put on type system. of c# type system's designers have paper on subject find interesting:
in practice, c# 4.0 , 5.0 compilers not implement infinitary type detector described in paper; rather, go unbounded recursion , crash.
i considered adding such code roslyn not recall time whether got in or not; i'll check source code when i'm in office next week.
a more gentle introduction problem can found in article here:
update: question asked andrew in original paper -- convertibility checking in world nominal subtyping , contravariant generics decidable in general? -- has been answered. not. see https://arxiv.org/abs/1605.05274. pleased note author noticed 1 of posts on subject -- not 1 -- , inspired attack problem.
Comments
Post a Comment