Skip to content

Commit 2283c0b

Browse files
committed
Move applied constructor types under modularity
1 parent 6f835ef commit 2283c0b

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
@@ -1333,12 +1333,16 @@ object Parsers {
13331333
/** Singleton ::= SimpleRef
13341334
* | SimpleLiteral
13351335
* | Singleton ‘.’ id
1336-
* -- not yet | Singleton ‘(’ Singletons ‘)’
1336+
* | Singleton ‘(’ Singletons ‘)’
13371337
* -- not yet | Singleton ‘[’ Types ‘]’
13381338
*/
13391339
def singleton(): Tree =
1340-
if isSimpleLiteral then simpleLiteral()
1341-
else dotSelectors(simpleRef())
1340+
val res =
1341+
if isSimpleLiteral then simpleLiteral()
1342+
else dotSelectors(simpleRef())
1343+
if in.token == LPAREN then
1344+
AppliedTypeTree(res, inParens(commaSeparated(() => singleton())))
1345+
else res
13421346

13431347
/** SimpleLiteral ::= [‘-’] integerLiteral
13441348
* | [‘-’] floatingPointLiteral
@@ -2050,7 +2054,7 @@ object Parsers {
20502054
/** SimpleType ::= SimpleLiteral
20512055
* | ‘?’ TypeBounds
20522056
* | SimpleType1
2053-
* | SimpleType ‘(’ Singletons ‘)’ -- under language.experimental.dependent, checked in Typer
2057+
* | SimpleType ‘(’ Singletons ‘)’ -- under language.experimental.modularity, checked in Typer
20542058
* Singletons ::= Singleton {‘,’ Singleton}
20552059
*/
20562060
def simpleType(): Tree =
@@ -2083,7 +2087,7 @@ object Parsers {
20832087
typeBounds().withSpan(Span(start, in.lastOffset, start))
20842088
else
20852089
def singletonArgs(t: Tree): Tree =
2086-
if in.token == LPAREN && in.featureEnabled(Feature.dependent)
2090+
if in.token == LPAREN && in.featureEnabled(Feature.modularity)
20872091
then singletonArgs(AppliedTypeTree(t, inParensWithCommas(commaSeparated(singleton))))
20882092
else t
20892093
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
@@ -2562,14 +2562,14 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
25622562

25632563
tree.args match
25642564
case arg :: _ if arg.isTerm =>
2565-
if Feature.dependentEnabled then
2565+
if Feature.enabled(Feature.modularity) then
25662566
tpt1.tpe.typeSymbol.primaryConstructor.typeRef.underlying match
25672567
case mt: MethodType =>
25682568
return TypeTree(mt.instantiate(tree.args.map((typedExpr(_).tpe))))
25692569
else
25702570
return errorTree(tree, dependentMsg)
25712571
case _ =>
2572-
2572+
25732573
val tparams = tpt1.tpe.typeParams
25742574
if tpt1.tpe.isError then
25752575
val args1 = tree.args.mapconserve(typedType(_))
@@ -2693,7 +2693,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
26932693
typeIndexedLambdaTypeTree(tree, tparams, body)
26942694

26952695
def typedTermLambdaTypeTree(tree: untpd.TermLambdaTypeTree)(using Context): Tree =
2696-
if Feature.dependentEnabled then
2696+
if Feature.enabled(Feature.modularity) then
26972697
errorTree(tree, em"Not yet implemented: (...) =>> ...")
26982698
else
26992699
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
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)