Skip to content

Commit 50a8347

Browse files
committed
Move applied constructor types under modularity
1 parent 09aa88d commit 50a8347

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1323,12 +1323,16 @@ object Parsers {
13231323
/** Singleton ::= SimpleRef
13241324
* | SimpleLiteral
13251325
* | Singleton ‘.’ id
1326-
* -- not yet | Singleton ‘(’ Singletons ‘)’
1326+
* | Singleton ‘(’ Singletons ‘)’
13271327
* -- not yet | Singleton ‘[’ Types ‘]’
13281328
*/
13291329
def singleton(): Tree =
1330-
if isSimpleLiteral then simpleLiteral()
1331-
else dotSelectors(simpleRef())
1330+
val res =
1331+
if isSimpleLiteral then simpleLiteral()
1332+
else dotSelectors(simpleRef())
1333+
if in.token == LPAREN then
1334+
AppliedTypeTree(res, inParens(commaSeparated(() => singleton())))
1335+
else res
13321336

13331337
/** SimpleLiteral ::= [‘-’] integerLiteral
13341338
* | [‘-’] floatingPointLiteral
@@ -2018,7 +2022,7 @@ object Parsers {
20182022
/** SimpleType ::= SimpleLiteral
20192023
* | ‘?’ TypeBounds
20202024
* | SimpleType1
2021-
* | SimpleType ‘(’ Singletons ‘)’ -- under language.experimental.dependent, checked in Typer
2025+
* | SimpleType ‘(’ Singletons ‘)’ -- under language.experimental.modularity, checked in Typer
20222026
* Singletons ::= Singleton {‘,’ Singleton}
20232027
*/
20242028
def simpleType(): Tree =
@@ -2051,7 +2055,7 @@ object Parsers {
20512055
typeBounds().withSpan(Span(start, in.lastOffset, start))
20522056
else
20532057
def singletonArgs(t: Tree): Tree =
2054-
if in.token == LPAREN && in.featureEnabled(Feature.dependent)
2058+
if in.token == LPAREN && in.featureEnabled(Feature.modularity)
20552059
then singletonArgs(AppliedTypeTree(t, inParensWithCommas(commaSeparated(singleton))))
20562060
else t
20572061
singletonArgs(simpleType1())

compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ object ErrorReporting {
294294

295295
def dependentMsg =
296296
"""Term-dependent types are experimental,
297-
|they must be enabled with a `experimental.dependent` language import or setting""".stripMargin.toMessage
297+
|they must be enabled with a `experimental.modularity` language import or setting""".stripMargin.toMessage
298298

299299
def err(using Context): Errors = new Errors
300300
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2520,14 +2520,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25202520

25212521
tree.args match
25222522
case arg :: _ if arg.isTerm =>
2523-
if Feature.dependentEnabled then
2523+
if Feature.enabled(Feature.modularity) then
25242524
tpt1.tpe.typeSymbol.primaryConstructor.typeRef.underlying match
25252525
case mt: MethodType =>
25262526
return TypeTree(mt.instantiate(tree.args.map((typedExpr(_).tpe))))
25272527
else
25282528
return errorTree(tree, dependentMsg)
25292529
case _ =>
2530-
2530+
25312531
val tparams = tpt1.tpe.typeParams
25322532
if tpt1.tpe.isError then
25332533
val args1 = tree.args.mapconserve(typedType(_))
@@ -2651,7 +2651,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26512651
typeIndexedLambdaTypeTree(tree, tparams, body)
26522652

26532653
def typedTermLambdaTypeTree(tree: untpd.TermLambdaTypeTree)(using Context): Tree =
2654-
if Feature.dependentEnabled then
2654+
if Feature.enabled(Feature.modularity) then
26552655
errorTree(tree, em"Not yet implemented: (...) =>> ...")
26562656
else
26572657
errorTree(tree, dependentMsg)

tests/neg/deptypes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ type Tensor2[T](m: Int)(n: Int) = Matrix[T](m, n) // error: not yet implemente
88

99
val x: Vec[Int](10) = ??? // error: not yet implemented
1010
val n = 10
11-
type T = Vec[String](n) // error: not yet implemented
11+
type T = Vec[String](n) // error: not yet implemented

tests/pos/applied_constructors.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import scala.language.experimental.modularity
2+
3+
class C(tracked val x: Int)
4+
class D(tracked val c: C)
5+
6+
object Test extends App {
7+
val c: C(42) = C(42)
8+
// val d: D(C(42)) = D(C(42))
9+
}

0 commit comments

Comments
 (0)