Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweaks to indent syntax #7363

Merged
merged 16 commits into from Oct 10, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Allow multi-variable pattern declarations

Allow multi-variable pattern declarations of the form

    val p1, ..., pn: T
  • Loading branch information
odersky committed Oct 5, 2019
commit 42409bf502bb91a7562644aab3ffbdb8d1adcc9b
@@ -49,9 +49,6 @@ object desugar {
case None, Exhaustive, IrrefutablePatDef, IrrefutableGenFrom
}

/** Info of a variable in a pattern: The named tree and its type */
private type VarInfo = (NameTree, Tree)

/** Is `name` the name of a method that can be invalidated as a compiler-generated
* case class method if it clashes with a user-defined method?
*/
@@ -1685,16 +1682,6 @@ object desugar {
TypeDef(tpnme.REFINE_CLASS, impl).withFlags(Trait)
}

/** If tree is of the form `id` or `id: T`, return its name and type, otherwise return None.
*/
private object IdPattern {
def unapply(tree: Tree)(implicit ctx: Context): Option[VarInfo] = tree match {
case id: Ident if id.name != nme.WILDCARD => Some(id, TypeTree())
case Typed(id: Ident, tpt) => Some((id, tpt))
case _ => None
}
}

/** Returns list of all pattern variables, possibly with their types,
* without duplicates
*/
@@ -345,6 +345,18 @@ trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped]
def bodyKind(body: List[Tree])(implicit ctx: Context): FlagSet =
body.foldLeft(NoInitsInterface)((fs, stat) => fs & defKind(stat))

/** Info of a variable in a pattern: The named tree and its type */
type VarInfo = (NameTree, Tree)

/** An extractor for trees of the form `id` or `id: T` */
object IdPattern {
def unapply(tree: Tree)(implicit ctx: Context): Option[VarInfo] = tree match {
case id: Ident if id.name != nme.WILDCARD => Some(id, TypeTree())
case Typed(id: Ident, tpt) => Some((id, tpt))
case _ => None
}
}

// todo: fill with other methods from TreeInfo that only apply to untpd.Tree's
}

@@ -3071,12 +3071,16 @@ object Parsers {
}
else EmptyTree
lhs match {
case (id @ Ident(name: TermName)) :: Nil if name != nme.WILDCARD =>
val vdef = ValDef(name, tpt, rhs)
case IdPattern(id, t) :: Nil if t.isEmpty =>
val vdef = ValDef(id.name.asTermName, tpt, rhs)
if (isBackquoted(id)) vdef.pushAttachment(Backquoted, ())
finalizeDef(vdef, mods, start)
case _ =>
if rhs.isEmpty then
def isAllIds = lhs.forall {
case IdPattern(id, t) => t.isEmpty
case _ => false
}
if rhs.isEmpty && !isAllIds then
syntaxError(ExpectedTokenButFound(EQUALS, in.token), Span(in.lastOffset))
PatDef(mods, lhs, tpt, rhs)
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.