Skip to content

Commit 67191b3

Browse files
committed
Move applied constructor types under modularity
1 parent b6b12f3 commit 67191b3

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

13441348
/** SimpleLiteral ::= [‘-’] integerLiteral
13451349
* | [‘-’] floatingPointLiteral
@@ -2051,7 +2055,7 @@ object Parsers {
20512055
/** SimpleType ::= SimpleLiteral
20522056
* | ‘?’ TypeBounds
20532057
* | SimpleType1
2054-
* | SimpleType ‘(’ Singletons ‘)’ -- under language.experimental.dependent, checked in Typer
2058+
* | SimpleType ‘(’ Singletons ‘)’ -- under language.experimental.modularity, checked in Typer
20552059
* Singletons ::= Singleton {‘,’ Singleton}
20562060
*/
20572061
def simpleType(): Tree =
@@ -2084,7 +2088,7 @@ object Parsers {
20842088
typeBounds().withSpan(Span(start, in.lastOffset, start))
20852089
else
20862090
def singletonArgs(t: Tree): Tree =
2087-
if in.token == LPAREN && in.featureEnabled(Feature.dependent)
2091+
if in.token == LPAREN && in.featureEnabled(Feature.modularity)
20882092
then singletonArgs(AppliedTypeTree(t, inParensWithCommas(commaSeparated(singleton))))
20892093
else t
20902094
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

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)