Skip to content

Commit 8be53e7

Browse files
committed
Merge pull request #70 from odersky/fix/annotations-in-patterns
Fixed two problems with annotated types in patterns
2 parents f28d7a9 + 722661c commit 8be53e7

File tree

5 files changed

+15
-10
lines changed

5 files changed

+15
-10
lines changed

docs/SyntaxSummary.txt

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,13 @@ grammar.
191191
CaseClause ::= `case' (Pattern [Guard] `=>' Block | INT) CaseDef(pat, guard?, block) // block starts at =>
192192

193193
Pattern ::= Pattern1 { `|' Pattern1 } Alternative(pats)
194-
Pattern1 ::= PatVar `:' SimpleType Bind(name, Typed(Ident(wildcard), tpe))
194+
Pattern1 ::= PatVar `:' RefinedType Bind(name, Typed(Ident(wildcard), tpe))
195195
| Pattern2
196196
Pattern2 ::= [varid `@'] InfixPattern Bind(name, pat)
197197
InfixPattern ::= SimplePattern { id [nl] SimplePattern } InfixOp(pat, op, pat)
198198
SimplePattern ::= PatVar Ident(wildcard)
199-
| Literal Bind(name, Ident(wildcard)) | Literal
200-
| `(' [Patterns] `)' Parens(pats) Tuple(pats)
199+
| Literal Bind(name, Ident(wildcard))
200+
| `(' [Patterns] `)' Parens(pats) Tuple(pats)
201201
| XmlPattern
202202
| SimplePattern1 [TypeArgs] [ArgumentPatterns]
203203
SimplePattern1 ::= Path

src/dotty/tools/dotc/parsing/Parsers.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ object Parsers {
810810

811811
def typeDependingOn(location: Location.Value): Tree =
812812
if (location == Location.InParens) typ()
813-
else if (location == Location.InPattern) withType()
813+
else if (location == Location.InPattern) refinedType()
814814
else infixType()
815815

816816
/* ----------- EXPRESSIONS ------------------------------------------------ */

src/dotty/tools/dotc/printing/PlainPrinter.scala

+1-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
103103
case tp: TypeRef =>
104104
toTextPrefix(tp.prefix) ~ selectionString(tp)
105105
case tp: RefinedType =>
106-
// return tp.toString // !!! DEBUG
107-
val parent :: (refined: List[RefinedType]) =
106+
val parent :: (refined: List[RefinedType @unchecked]) =
108107
refinementChain(tp).reverse
109108
toTextLocal(parent) ~ "{" ~ Text(refined map toTextRefinement, "; ").close ~ "}"
110109
case AndType(tp1, tp2) =>

src/dotty/tools/dotc/typer/Typer.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
826826
}
827827

828828
def typedAnnotated(tree: untpd.Annotated, pt: Type)(implicit ctx: Context): Tree = track("typedAnnotated") {
829-
val annot1 = typed(tree.annot, defn.AnnotationClass.typeRef)
829+
val annot1 = typedExpr(tree.annot, defn.AnnotationClass.typeRef)
830830
val arg1 = typed(tree.arg, pt)
831831
if (ctx.mode is Mode.Type)
832832
assignType(cpy.Annotated(tree, annot1, arg1), annot1, arg1)

tests/pos/Patterns.scala

+9-3
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,23 @@ object Patterns {
1010
case (digit, str) => true
1111
case _ => false
1212
}
13-
13+
14+
(xs: Any) match {
15+
case x: Int @unchecked => true
16+
case xs: List[Int @ unchecked] => true
17+
case _ => false
18+
}
19+
1420
def sum(xs: List[Int]): Int = xs match {
1521
case Nil => 0
1622
case x :: xs1 => x + sum(xs1)
1723
}
18-
24+
1925
def len[T](xs: List[T]): Int = xs match {
2026
case _ :: xs1 => 1 + len(xs1)
2127
case Nil => 0
2228
}
23-
29+
2430
final def sameLength[T](xs: List[T], ys: List[T]): Boolean = xs match {
2531
case _ :: xs1 =>
2632
ys match {

0 commit comments

Comments
 (0)