File tree Expand file tree Collapse file tree 3 files changed +19
-16
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +19
-16
lines changed Original file line number Diff line number Diff line change @@ -49,9 +49,6 @@ object desugar {
4949 case None , Exhaustive , IrrefutablePatDef , IrrefutableGenFrom
5050 }
5151
52- /** Info of a variable in a pattern: The named tree and its type */
53- private type VarInfo = (NameTree , Tree )
54-
5552 /** Is `name` the name of a method that can be invalidated as a compiler-generated
5653 * case class method if it clashes with a user-defined method?
5754 */
@@ -1685,16 +1682,6 @@ object desugar {
16851682 TypeDef (tpnme.REFINE_CLASS , impl).withFlags(Trait )
16861683 }
16871684
1688- /** If tree is of the form `id` or `id: T`, return its name and type, otherwise return None.
1689- */
1690- private object IdPattern {
1691- def unapply (tree : Tree )(implicit ctx : Context ): Option [VarInfo ] = tree match {
1692- case id : Ident if id.name != nme.WILDCARD => Some (id, TypeTree ())
1693- case Typed (id : Ident , tpt) => Some ((id, tpt))
1694- case _ => None
1695- }
1696- }
1697-
16981685 /** Returns list of all pattern variables, possibly with their types,
16991686 * without duplicates
17001687 */
Original file line number Diff line number Diff line change @@ -345,6 +345,18 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
345345 def bodyKind (body : List [Tree ])(implicit ctx : Context ): FlagSet =
346346 body.foldLeft(NoInitsInterface )((fs, stat) => fs & defKind(stat))
347347
348+ /** Info of a variable in a pattern: The named tree and its type */
349+ type VarInfo = (NameTree , Tree )
350+
351+ /** An extractor for trees of the form `id` or `id: T` */
352+ object IdPattern {
353+ def unapply (tree : Tree )(implicit ctx : Context ): Option [VarInfo ] = tree match {
354+ case id : Ident if id.name != nme.WILDCARD => Some (id, TypeTree ())
355+ case Typed (id : Ident , tpt) => Some ((id, tpt))
356+ case _ => None
357+ }
358+ }
359+
348360 // todo: fill with other methods from TreeInfo that only apply to untpd.Tree's
349361}
350362
Original file line number Diff line number Diff line change @@ -3052,12 +3052,16 @@ object Parsers {
30523052 }
30533053 else EmptyTree
30543054 lhs match {
3055- case (id @ Ident ( name : TermName )) :: Nil if name != nme. WILDCARD =>
3056- val vdef = ValDef (name, tpt, rhs)
3055+ case IdPattern (id, t) :: Nil if t.isEmpty =>
3056+ val vdef = ValDef (id. name.asTermName , tpt, rhs)
30573057 if (isBackquoted(id)) vdef.pushAttachment(Backquoted , ())
30583058 finalizeDef(vdef, mods, start)
30593059 case _ =>
3060- if rhs.isEmpty then
3060+ def isAllIds = lhs.forall {
3061+ case IdPattern (id, t) => t.isEmpty
3062+ case _ => false
3063+ }
3064+ if rhs.isEmpty && ! isAllIds then
30613065 syntaxError(ExpectedTokenButFound (EQUALS , in.token), Span (in.lastOffset))
30623066 PatDef (mods, lhs, tpt, rhs)
30633067 }
You can’t perform that action at this time.
0 commit comments