Eugene Vigdorchik | 13 Oct 18:40

illegal match allowed by scalac

Hi,
the following session fails with MatchError for obvious reasons, but the compiler is happy with this code. Should it signal it? (I'm using 2.7.2-RC2)
 
scala> class ScType
defined class ScType

scala> var t : Option[ScType] = Some(new ScType)
t: Option[ScType] = Some(ScType <at> 17ccb2f)

scala> class ScalaResolveResult
defined class ScalaResolveResult

scala> t match {case Some(r : ScalaResolveResult) => r case None => null}
scala.MatchError: Some(ScType <at> 17ccb2f)
        at .<init>(<console>:8)
        at .<clinit>(<console>)
        at RequestResult$.<init>(<console>:3)
        at RequestResult$.<clinit>(<console>)
        at RequestResult$result(<console>)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkn...
scala>

Eugene.
martin odersky | 13 Oct 18:49
Favicon

Re: illegal match allowed by scalac

I think at the moment exhaustiveness checking is done only for
constructor patterns, not for type patterns like the one your wrote.

Cheers

 -- Martin

On Mon, Oct 13, 2008 at 6:44 PM, Eugene Vigdorchik
<eugene.vigdorchik <at> gmail.com> wrote:
> Hi,
> the following session fails with MatchError for obvious reasons, but the
> compiler is happy with this code. Should it signal it? (I'm using 2.7.2-RC2)
>
> scala> class ScType
> defined class ScType
>
> scala> var t : Option[ScType] = Some(new ScType)
> t: Option[ScType] = Some(ScType <at> 17ccb2f)
>
> scala> class ScalaResolveResult
> defined class ScalaResolveResult
>
> scala> t match {case Some(r : ScalaResolveResult) => r case None => null}
> scala.MatchError: Some(ScType <at> 17ccb2f)
>         at .<init>(<console>:8)
>         at .<clinit>(<console>)
>         at RequestResult$.<init>(<console>:3)
>         at RequestResult$.<clinit>(<console>)
>         at RequestResult$result(<console>)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkn...
> scala>
>
> Eugene.
>

Eugene Vigdorchik | 13 Oct 19:07

Re: illegal match allowed by scalac

I think it is not about exhaustiveness, but rather typed pattern not conforming to expected type. Does scala allow this?

On Mon, Oct 13, 2008 at 8:49 PM, martin odersky <martin.odersky <at> epfl.ch> wrote:
I think at the moment exhaustiveness checking is done only for
constructor patterns, not for type patterns like the one your wrote.

Cheers

 -- Martin


On Mon, Oct 13, 2008 at 6:44 PM, Eugene Vigdorchik
<eugene.vigdorchik <at> gmail.com> wrote:
> Hi,
> the following session fails with MatchError for obvious reasons, but the
> compiler is happy with this code. Should it signal it? (I'm using 2.7.2-RC2)
>
> scala> class ScType
> defined class ScType
>
> scala> var t : Option[ScType] = Some(new ScType)
> t: Option[ScType] = Some(ScType <at> 17ccb2f)
>
> scala> class ScalaResolveResult
> defined class ScalaResolveResult
>
> scala> t match {case Some(r : ScalaResolveResult) => r case None => null}
> scala.MatchError: Some(ScType <at> 17ccb2f)
>         at .<init>(<console>:8)
>         at .<clinit>(<console>)
>         at RequestResult$.<init>(<console>:3)
>         at RequestResult$.<clinit>(<console>)
>         at RequestResult$result(<console>)
>         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>         at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
>         at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unkn...
> scala>
>
> Eugene.
>

Favicon

Re: illegal match allowed by scalac

Eugene Vigdorchik wrote:
> I think it is not about exhaustiveness, but rather typed pattern not 
> conforming to expected type. 

Right.  I would have thought the same code that handles GADT refinements 
would have indicated that the case could not possibly typecheck.


Gmane