Skip to content

Commit 7a14c05

Browse files
committed
Add assert that refine infos are legal wrt refined names
1 parent d0162ae commit 7a14c05

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2066,6 +2066,9 @@ object Types {
20662066
*/
20672067
abstract case class RefinedType(parent: Type, refinedName: Name, refinedInfo: Type) extends RefinedOrRecType {
20682068

2069+
if (refinedName.isTermName) assert(refinedInfo.isInstanceOf[TermType])
2070+
else assert(refinedInfo.isInstanceOf[TypeType])
2071+
20692072
override def underlying(implicit ctx: Context) = parent
20702073

20712074
private def badInst =

tests/run/i2037.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
malformed type

tests/run/i2037.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import dotty.tools.dotc._
2+
import core._
3+
import Types._
4+
import Contexts._
5+
import Symbols._
6+
import Decorators._
7+
8+
object Test {
9+
def f(implicit ctx: Context) = {
10+
val badType =
11+
RefinedType(
12+
ctx.requiredClassRef("scala.collection.AbstractIterator"),
13+
"GroupedIterator".toTypeName,
14+
TypeRef(ctx.requiredClassRef("scala.collection.AbstractIterator"), "GroupedIterator".toTypeName))
15+
badType.member("GroupedIterator".toTypeName)
16+
// badType.member("T".toTypeName)
17+
}
18+
def main(args: Array[String]): Unit = {
19+
implicit val ctx = (new ContextBase).initialCtx
20+
ctx.base.initialize()
21+
try f
22+
catch {
23+
case ex: AssertionError => println("malformed type")
24+
}
25+
}
26+
}

0 commit comments

Comments
 (0)