Re: Unexpected compilation error with generic sealed interface
On 2020-12-28T11:41:36 -0500 Vicente Romero wrote: > Hi, > > I believe this to be the same issue already addressed in [1], which has > already been fixed in 16 and should be forward-ported to 17, Looks like it, yes! Didn't realize the same code had been submitted there. To be clear: The original symptom was an actual compiler crash. Now we just get a compilation error ("I cannot be converted to C"). An error is obviously better than a crash, but I don't think this code should result in an error at all. -- Mark Raynsford | https://www.io7m.com
Re: Unexpected compilation error with generic sealed interface
On 12/28/20 11:53 AM, Mark Raynsford wrote: On 2020-12-28T11:41:36 -0500 Vicente Romero wrote: Hi, I believe this to be the same issue already addressed in [1], which has already been fixed in 16 and should be forward-ported to 17, Looks like it, yes! Didn't realize the same code had been submitted there. I have realized that your code is almost the same as the bug I was referring to but it is not exactly equal. What you are reporting is another issue, it is great that you have discovered and reported it while we still have time to fix it in 16. I will file a bug an propose a fix for it. To be clear: The original symptom was an actual compiler crash. Now we just get a compilation error ("I cannot be converted to C"). An error is obviously better than a crash, but I don't think this code should result in an error at all. Thanks! Vicente
Re: Unexpected compilation error with generic sealed interface
Hi, I believe this to be the same issue already addressed in [1], which has already been fixed in 16 and should be forward-ported to 17, Thanks, Vicente [1] https://bugs.openjdk.java.net/browse/JDK-8258662 On 12/28/20 5:33 AM, Mark Raynsford wrote: On 2020-12-27T23:40:50 +0100 Remi Forax wrote: Hi Mark, this is an interesting snippet, while i struggle to understand why someone want to write a code like that, I is parametrized by T but the only possible subclass implements I so T is useless here, anyway, the compiler should not reject that code so it's a bug. Hello! I think the original code was a collection of little functional data structures (Option, List, etc) to try out the combination of records and sealed classes. The code above is the result of removing things one by one until the result was a minimal example that would trigger the error.
Re: Unexpected compilation error with generic sealed interface
On 2020-12-27T23:40:50 +0100 Remi Forax wrote: > Hi Mark, > this is an interesting snippet, while i struggle to understand why someone > want to write a code like that, I is parametrized by T but the only possible > subclass implements I so T is useless here, > anyway, the compiler should not reject that code so it's a bug. Hello! I think the original code was a collection of little functional data structures (Option, List, etc) to try out the combination of records and sealed classes. The code above is the result of removing things one by one until the result was a minimal example that would trigger the error. -- Mark Raynsford | https://www.io7m.com
Unexpected compilation error with generic sealed interface
Hello! A friend of mine handed me this example that fails to compile using JDK 17 EA 3: ~~ final class SealedExample { private SealedExample() { } // Compiles if you remove `sealed` or if `I` is not generic. sealed interface I { final class C implements I { } } static void f(final I x) { if (x instanceof I.C) { } } } ~~ The error is: ~~ src/main/java/SealedRecord.java:14: error: incompatible types: I cannot be converted to C if (x instanceof I.C) { ^ 1 error ~~ The error goes away if you remove the word "sealed" from the interface. In her words: "It breaks simple things like Option.". I can see the reasoning required on behalf of the compiler: You've handed me an I, and by the definition of I, there's exactly one class that could yield an I: C. I'm unsure of whether the compiler should be rejecting these definitions or not. -- Mark Raynsford | https://www.io7m.com
Re: Unexpected compilation error with generic sealed interface
- Mail original - > De: "mark" > À: "amber-spec-experts" > Envoyé: Dimanche 27 Décembre 2020 22:04:43 > Objet: Unexpected compilation error with generic sealed interface > Hello! > > A friend of mine handed me this example that fails to compile using > JDK 17 EA 3: > > ~~ > final class SealedExample > { > private SealedExample() > { > > } > > // Compiles if you remove `sealed` or if `I` is not generic. > sealed interface I { >final class C implements I { } > } > > static void f(final I x) { >if (x instanceof I.C) { > >} > } > } > ~~ > > The error is: > > ~~ > src/main/java/SealedRecord.java:14: error: incompatible types: > I cannot be converted to C if (x instanceof I.C) { >^ > 1 error > ~~ > > The error goes away if you remove the word "sealed" from the > interface. In her words: "It breaks simple things like Option.". > > I can see the reasoning required on behalf of the compiler: You've > handed me an I, and by the definition of I, there's exactly one > class that could yield an I: C. > > I'm unsure of whether the compiler should be rejecting these > definitions or not. Hi Mark, this is an interesting snippet, while i struggle to understand why someone want to write a code like that, I is parametrized by T but the only possible subclass implements I so T is useless here, anyway, the compiler should not reject that code so it's a bug. I've also tested with latest Eclipse and IntelliJ and in both cases it compiles fine. > > -- > Mark Raynsford | https://www.io7m.com Rémi