- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Failing to match on singleton type
This is using 2.9.1 - I can't find any matching issues
The complaint is seems to be that Wuffles is not of Wuffles.type
OK. Is this a new bug, a bug I can't find in JIRA, or a feature? Seems to be fixable by:
Chris
scala> object Wufflesdefined module Wuffles
scala> (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) => println("Woof"); case _ => println("Meow") }<console>:10: error: pattern type is incompatible with expected type; found : object Wuffles required: Wuffles.type (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) => println("Woof"); case _ => println("Meow") } ^
The complaint is seems to be that Wuffles is not of Wuffles.type
scala> Wufflesres10: Wuffles.type = Wuffles$@11dc088
OK. Is this a new bug, a bug I can't find in JIRA, or a feature? Seems to be fixable by:
scala> (Some(Wuffles): Option[Wuffles.type]) match { case Some(wuffles: Wuffles.type) => println("Woof"); case _ => println("Meow") }Woof
Chris










RE: Failing to match on singleton type
From: oxbow_lakes [at] hotmail [dot] com
To: scala-user [at] googlegroups [dot] com
Subject: [scala-user] Failing to match on singleton type
Date: Tue, 24 Jan 2012 11:02:55 +0000
.ExternalClass .ecxhmmessage P {padding:0px;} .ExternalClass body.ecxhmmessage {font-size:10pt;font-family:Tahoma;} This is using 2.9.1 - I can't find any matching issues
The complaint is seems to be that Wuffles is not of Wuffles.type
OK. Is this a new bug, a bug I can't find in JIRA, or a feature? Seems to be fixable by:
Chris
Re: Failing to match on singleton type
I have no preliminary knowledge in this, but here are some clues :
> object W
defined module W
> (Some(W): Option[_ >: W.type]) match {
> case Some(W) => "yo"
> case None => "no"
> }
res21: java.lang.String = yo
also :
> class A
defined class A
> object B extends A
defined module B
> (Some(B): Option[A]) match {case Some(B) => "yo"; case None => "no"}
res14: java.lang.String = yo
What I suspect is that B.type is an artificial type only meant for
reflection, and that doesn't appear in the type hierarchy of your
program, from the compiler point of view.
B.isInstanceOf[B.type] will yield true. Some compiler magic for
reflection purposes ? Maybe structural types are involved ?
Waiting for the big shots to answer here :).
Alex
2012/1/25, Chris Marshall :
>
> Reported:
> https://issues.scala-lang.org/browse/SI-5406
>
> From: oxbow_lakes [at] hotmail [dot] com
> To: scala-user [at] googlegroups [dot] com
> Subject: [scala-user] Failing to match on singleton type
> Date: Tue, 24 Jan 2012 11:02:55 +0000
>
>
>
>
>
>
>
> This is using 2.9.1 - I can't find any matching issues
> scala> object Wufflesdefined module Wuffles
> scala> (Some(Wuffles): Option[Wuffles.type]) match { case Some(Wuffles) =>
> println("Woof"); case _ => println("Meow") }:10: error: pattern
> type is incompatible with expected type; found : object Wuffles required:
> Wuffles.type (Some(Wuffles): Option[Wuffles.type]) match { case
> Some(Wuffles) => println("Woof"); case _ => println("Meow") }
> ^
> The complaint is seems to be that Wuffles is not of Wuffles.type
> scala> Wufflesres10: Wuffles.type = Wuffles$@11dc088
> OK. Is this a new bug, a bug I can't find in JIRA, or a feature? Seems to be
> fixable by:
> scala> (Some(Wuffles): Option[Wuffles.type]) match { case Some(wuffles:
> Wuffles.type) => println("Woof"); case _ => println("Meow") }Woof
>
> Chris
Re: Failing to match on singleton type
this duplicity has caused trouble at several times in the past, but I can't really provide any insight into why there cannot only be one (I can't even seem to find a specific ticket about this in jira)