Skip to content

Commit 4f5e7f5

Browse files
committed
Addressed some reviewer comments.
1 parent 2715a53 commit 4f5e7f5

File tree

7 files changed

+24
-13
lines changed

7 files changed

+24
-13
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,8 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
567567
// Need to be more permissive when checking later phases, applications may have been rewritten
568568
isSubType(tp1, tp2.resType)
569569
case tp1: AppliedTermRef =>
570-
tp1.args.size == tp2.args.size && isSubType(tp1.fn, tp2.fn) &&
571-
(tp1.args zip tp2.args).forall(t => isSubType(t._1, t._2))
570+
sameLength(tp1.args, tp2.args) && isSubType(tp1.fn, tp2.fn) &&
571+
(tp1.args, tp2.args).zipped.forall(isSubType)
572572
case _ => fourthTry
573573
}
574574
compareAppliedTerm

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,7 +2177,7 @@ object Types {
21772177
abstract case class AppliedTermRef(fn: /*TermRef | AppliedTermRef*/ SingletonType, args: List[Type])
21782178
extends CachedProxyType with SingletonType
21792179
{
2180-
protected[this] var myResType: Type = _
2180+
private[this] var myResType: Type = _
21812181
def resType(implicit ctx: Context): Type = {
21822182
if (myResType == null)
21832183
fn.widen match {
@@ -2188,7 +2188,7 @@ object Types {
21882188

21892189
def underlying(implicit ctx: Context): Type = resType
21902190

2191-
def derivedAppliedTerm(fn: Type, args: List[Type])(implicit ctx: Context): Type =
2191+
def derivedAppliedTermRef(fn: Type, args: List[Type])(implicit ctx: Context): Type =
21922192
if ((this.fn eq fn) && (this.args eq args)) this
21932193
else AppliedTermRef(fn, args)
21942194

@@ -3961,8 +3961,8 @@ object Types {
39613961
tp.derivedSuperType(thistp, supertp)
39623962
protected def derivedAppliedType(tp: AppliedType, tycon: Type, args: List[Type]): Type =
39633963
tp.derivedAppliedType(tycon, args)
3964-
protected def derivedAppliedTerm(tp: AppliedTermRef, fn: Type, args: List[Type]): Type =
3965-
tp.derivedAppliedTerm(fn, args)
3964+
protected def derivedAppliedTermRef(tp: AppliedTermRef, fn: Type, args: List[Type]): Type =
3965+
tp.derivedAppliedTermRef(fn, args)
39663966
protected def derivedAndType(tp: AndType, tp1: Type, tp2: Type): Type =
39673967
tp.derivedAndType(tp1, tp2)
39683968
protected def derivedOrType(tp: OrType, tp1: Type, tp2: Type): Type =
@@ -4019,7 +4019,7 @@ object Types {
40194019
derivedAppliedType(tp, this(tp.tycon), mapArgs(tp.args, tp.typeParams))
40204020

40214021
case tp: AppliedTermRef =>
4022-
derivedAppliedTerm(tp, this(tp.fn), tp.args.mapConserve(this))
4022+
derivedAppliedTermRef(tp, this(tp.fn), tp.args.mapConserve(this))
40234023

40244024
case tp: RefinedType =>
40254025
derivedRefinedType(tp, this(tp.parent), this(tp.refinedInfo))
@@ -4317,10 +4317,10 @@ object Types {
43174317
else tp.derivedAppliedType(tycon, args)
43184318
}
43194319

4320-
override protected def derivedAppliedTerm(tp: AppliedTermRef, fn: Type, args: List[Type]): Type =
4320+
override protected def derivedAppliedTermRef(tp: AppliedTermRef, fn: Type, args: List[Type]): Type =
43214321
fn match {
43224322
case Range(fnLo, fnHi) =>
4323-
range(derivedAppliedTerm(tp, fnLo, args), derivedAppliedTerm(tp, fnHi, args))
4323+
range(derivedAppliedTermRef(tp, fnLo, args), derivedAppliedTermRef(tp, fnHi, args))
43244324
case _ =>
43254325
if (fn.isBottomType) {
43264326
fn
@@ -4330,9 +4330,9 @@ object Types {
43304330
case Range(lo, hi) => loBuf += lo; hiBuf += hi
43314331
case arg => loBuf += arg; hiBuf += arg
43324332
}
4333-
range(tp.derivedAppliedTerm(fn, loBuf.toList), tp.derivedAppliedTerm(fn, hiBuf.toList))
4333+
range(tp.derivedAppliedTermRef(fn, loBuf.toList), tp.derivedAppliedTermRef(fn, hiBuf.toList))
43344334
} else {
4335-
tp.derivedAppliedTerm(fn, args)
4335+
tp.derivedAppliedTermRef(fn, args)
43364336
}
43374337
}
43384338

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ Standard-Section: "ASTs" TopLevelStat*
163163
methodType(_, _) Length result_Type NamesTypes // needed for refinements
164164
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
165165
SHAREDtype type_ASTRef
166+
APPLIEDTERMREF Length fn_Type arg_Type*
166167
NamesTypes = NameType*
167168
NameType = paramName_NameRef typeOrBounds_ASTRef
168169
@@ -401,6 +402,7 @@ object TastyFormat {
401402
final val ANNOTATION = 172
402403
final val TERMREFin = 173
403404
final val TYPEREFin = 174
405+
final val APPLIEDTERMREF = 175
404406

405407
// In binary: 101100EI
406408
// I = implicit method type
@@ -416,7 +418,6 @@ object TastyFormat {
416418
METHODtype + implicitOffset + erasedOffset
417419
}
418420

419-
final val APPLIEDTERMREF = 180
420421
final val HOLE = 255
421422

422423
final val firstNatTreeTag = SHAREDterm
@@ -430,7 +431,7 @@ object TastyFormat {
430431
firstNatTreeTag <= tag && tag <= SYMBOLconst ||
431432
firstASTTreeTag <= tag && tag <= SINGLETONtpt ||
432433
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
433-
firstLengthTreeTag <= tag && tag <= TYPEREFin ||
434+
firstLengthTreeTag <= tag && tag <= ERASEDIMPLICITMETHODtype ||
434435
tag == HOLE
435436

436437
def isParamTag(tag: Int) = tag == PARAM || tag == TYPEPARAM
@@ -617,6 +618,7 @@ object TastyFormat {
617618
case ANNOTATION => "ANNOTATION"
618619
case PRIVATEqualified => "PRIVATEqualified"
619620
case PROTECTEDqualified => "PROTECTEDqualified"
621+
case APPLIEDTERMREF => "APPLIEDTERMREF"
620622
case HOLE => "HOLE"
621623
}
622624

compiler/src/dotty/tools/dotc/core/tasty/TastyPrinter.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
7272
case METHODtype | IMPLICITMETHODtype | ERASEDMETHODtype | ERASEDIMPLICITMETHODtype | POLYtype | TYPELAMBDAtype =>
7373
printTree()
7474
until(end) { printName(); printTree() }
75+
case APPLIEDTERMREF =>
76+
printTree()
77+
until(end) { printTree() }
7578
case PARAMtype =>
7679
printNat(); printNat()
7780
case _ =>

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,7 @@ object Parsers {
855855
* | `(' ArgTypes `)'
856856
* | `_' TypeBounds
857857
* | Refinement
858+
* | `{` PostfixExpr `}`
858859
* | Literal
859860
*/
860861
def simpleType(): Tree = simpleTypeRest {

docs/docs/internals/syntax.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ SimpleType ::= SimpleType TypeArgs
137137
| ‘(’ ArgTypes ‘)’ Tuple(ts)
138138
| ‘_’ TypeBounds
139139
| Refinement RefinedTypeTree(EmptyTree, refinement)
140+
| ‘{’ PostfixExpr ‘}’ SingletonTypeTree(expr)
140141
| SimpleLiteral SingletonTypeTree(l)
141142
ArgTypes ::= Type {‘,’ Type}
142143
| NamedTypeArg {‘,’ NamedTypeArg}

tests/pos/appliedTerm.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
object SimpleEqs {
22
val x = 1
33
val y: {x} = x
4+
5+
type YPlusOne = {y + 1}
6+
47
implicitly[{x + 1} =:= {y + 1}]
8+
implicitly[{x + 1} =:= YPlusOne]
59
}
610

711

0 commit comments

Comments
 (0)