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

PlaceholderChecks: add ApplyType and New #2754

Merged
merged 2 commits into from
May 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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