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:

https://www.microsoft.com/en-us/research/publication/on-decidability-of-nominal-subtyping-with-variance/

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:

http://blogs.msdn.com/b/ericlippert/archive/2008/05/07/covariance-and-contravariance-part-twelve-to-infinity-but-not-beyond.aspx

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

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -