Skip to content

Fix #10681: Reject applied HK types in term positions #10774

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

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 13 additions & 1 deletion compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,17 @@ trait Applications extends Compatibility {
* Fallback if this fails: try to convert `E` to `new E`.
*/
def typedFunPart(fn: untpd.Tree, pt: Type)(using Context): Tree =
/** typedFunPart should only adapt E to new E
* when we're applying E to some term parameters: val x = String() works and
* expands to val x = new String(), but val x = String doesn't, it should be
* the same for the aliases of String.
*/
def canTryNew(pt: Type)(using Context): Boolean =
pt match
case tp: FunProto => true
case tp: PolyProto => canTryNew(tp.resType)
case _ => false

tryEither {
typedExpr(fn, pt)
} { (result, tstate) =>
Expand All @@ -856,7 +867,8 @@ trait Applications extends Compatibility {
then nuState.commit() // nuState messages are more interesting that tstate's "not found"
else tstate.commit() // it's "not found" both ways; keep original message
result
if untpd.isPath(fn) then tryNew(untpd)(fn, pt, fallBack)
if untpd.isPath(fn) && canTryNew(pt) then
tryNew(untpd)(fn, pt, fallBack)
else fallBack(ctx.typerState)
}

Expand Down
97 changes: 97 additions & 0 deletions tests/neg/i10681.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
-- [E006] Not Found Error: tests/neg/i10681.scala:2:15 ---------------------
2 |val testGood = TestGood
| ^^^^^^^^
| Not found: TestGood

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:5:14 ---------------------
5 |val testBad = TestBad[Nothing]
| ^^^^^^^
| Not found: TestBad

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:6:18 ---------------------
6 |val testBadNoAp = TestBad
| ^^^^^^^
| Not found: TestBad

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:9:15 ---------------------
9 |val testBad2 = TestBad2[Nothing]
| ^^^^^^^^
| Not found: TestBad2

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:10:19 --------------------
10 |val testBad2NoAp = TestBad2
| ^^^^^^^^
| Not found: TestBad2

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:13:19 --------------------
13 |val testBad3NoAp = TestBad3
| ^^^^^^^^
| Not found: TestBad3

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:14:24 --------------------
14 |val testBad3PartialAp = TestBad3[String]
| ^^^^^^^^
| Not found: TestBad3

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:15:15 --------------------
15 |val testBad3 = TestBad3[String][String]
| ^^^^^^^^
| Not found: TestBad3

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:18:18 --------------------
18 |val testBad4Ap0 = TestBad4
| ^^^^^^^^
| Not found: TestBad4

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:19:18 --------------------
19 |val testBad4Ap1 = TestBad4[Nothing]
| ^^^^^^^^
| Not found: TestBad4

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:20:18 --------------------
20 |val testBad4Ap2 = TestBad4[Nothing, Nothing]
| ^^^^^^^^
| Not found: TestBad4

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:21:18 --------------------
21 |val testBad4Ap3 = TestBad4[Nothing, Nothing][Nothing]
| ^^^^^^^^
| Not found: TestBad4

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:22:18 --------------------
22 |val testBad4Ap4 = TestBad4[Nothing, Nothing][Nothing, Nothing]
| ^^^^^^^^
| Not found: TestBad4

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:23:18 --------------------
23 |val testBad4Ap5 = TestBad4[Nothing, Nothing][Nothing, Nothing][Nothing]
| ^^^^^^^^
| Not found: TestBad4

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:27:12 --------------------
27 |val test1 = PartialApplication[String]
| ^^^^^^^^^^^^^^^^^^
| Not found: PartialApplication

longer explanation available when compiling with `-explain`
-- [E006] Not Found Error: tests/neg/i10681.scala:28:12 --------------------
28 |val test2 = Curried[String][String]
| ^^^^^^^
| Not found: Curried

longer explanation available when compiling with `-explain`
16 errors found
28 changes: 28 additions & 0 deletions tests/neg/i10681.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
type TestGood = String
val testGood = TestGood // error

type TestBad[A] = String
val testBad = TestBad[Nothing] // error
val testBadNoAp = TestBad // error

type TestBad2 = [A] =>> String
val testBad2 = TestBad2[Nothing] // error
val testBad2NoAp = TestBad2 // error

type TestBad3[A] = [B] =>> String
val testBad3NoAp = TestBad3 // error
val testBad3PartialAp = TestBad3[String] // error
val testBad3 = TestBad3[String][String] // error

type TestBad4[A, B] = [C, D] =>> [E] =>> String
val testBad4Ap0 = TestBad4 // error
val testBad4Ap1 = TestBad4[Nothing] // error
val testBad4Ap2 = TestBad4[Nothing, Nothing] // error
val testBad4Ap3 = TestBad4[Nothing, Nothing][Nothing] // error
val testBad4Ap4 = TestBad4[Nothing, Nothing][Nothing, Nothing] // error
val testBad4Ap5 = TestBad4[Nothing, Nothing][Nothing, Nothing][Nothing] // error

type Curried = [X] =>> [Y] =>> String
type PartialApplication[X] = Curried[String][X]
val test1 = PartialApplication[String] // error
val test2 = Curried[String][String] // error