Skip to content

Commit

Permalink
Merge pull request #2754 from kitbellew/2754
Browse files Browse the repository at this point in the history
PlaceholderChecks: add ApplyType and New
  • Loading branch information
kitbellew committed May 16, 2022
2 parents b041fd4 + 9ae65f8 commit 2f5711c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ object PlaceholderChecks {
case t: Term.ApplyInfix =>
isBlockPlaceholder(t.args) || { queue += t.lhs; queue ++= t.args; iter }
case t: Term.ApplyUnary => queue += t.arg; iter
case t: Term.ApplyType => queue += t.fun; iter
case t: Term.New => queue += t.init; iter
case t: Term.Repeated => queue += t.expr; iter
case _: Term.AnonymousFunction => queue.nonEmpty && iter
case t => t.children.exists(isPlaceholder) || queue.nonEmpty && iter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,52 @@ class SyntacticSuite extends scala.meta.tests.parsers.ParseSuite {
)
}
}

test("anonymous function with new") {
checkTree(q"foo map (new foo(_))") {
Term.ApplyInfix(
Term.Name("foo"),
Term.Name("map"),
Nil,
List(
Term.AnonymousFunction(
Term.New(Init(Type.Name("foo"), Name(""), List(List(Term.Placeholder()))))
)
)
)
}
}

test("anonymous function with select") {
checkTree(q"foo map (foo(_).bar)") {
Term.ApplyInfix(
Term.Name("foo"),
Term.Name("map"),
Nil,
List(
Term.AnonymousFunction(
Term.Select(Term.Apply(Term.Name("foo"), List(Term.Placeholder())), Term.Name("bar"))
)
)
)
}
}

test("anonymous function with apply type") {
checkTree(q"foo map (_.foo[A])") {
Term.ApplyInfix(
Term.Name("foo"),
Term.Name("map"),
Nil,
List(
Term.AnonymousFunction(
Term.ApplyType(Term.Select(Term.Placeholder(), Term.Name("foo")), List(Type.Name("A")))
)
)
)
}
}

test("#2317 init block") {
checkStat(
"""new Foo({
Expand Down

0 comments on commit 2f5711c

Please sign in to comment.