Skip to content

Commit 2cdfcbb

Browse files
Merge pull request #11009 from dotty-staging/fix-#9328
Avoid NoDenotation.owner in some situations
2 parents 2be3291 + 8544c30 commit 2cdfcbb

File tree

3 files changed

+32
-10
lines changed

3 files changed

+32
-10
lines changed

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -1393,10 +1393,10 @@ object SymDenotations {
13931393
def thisType(using Context): Type = NoPrefix
13941394

13951395
def typeRef(using Context): TypeRef =
1396-
TypeRef(owner.thisType, symbol)
1396+
TypeRef(maybeOwner.thisType, symbol)
13971397

13981398
def termRef(using Context): TermRef =
1399-
TermRef(owner.thisType, symbol)
1399+
TermRef(maybeOwner.thisType, symbol)
14001400

14011401
/** The typeRef applied to its own type parameters */
14021402
def appliedRef(using Context): Type =

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -1657,14 +1657,15 @@ sealed class TermRefSet(using Context):
16571657

16581658
def += (ref: TermRef): Unit =
16591659
val pre = ref.prefix
1660-
val sym = ref.symbol.asTerm
1661-
elems.get(sym) match
1662-
case null =>
1663-
elems.put(sym, pre)
1664-
case prefix: Type =>
1665-
if !(prefix =:= pre) then elems.put(sym, pre :: prefix :: Nil)
1666-
case prefixes: List[Type] =>
1667-
if !prefixes.exists(_ =:= pre) then elems.put(sym, pre :: prefixes)
1660+
if ref.symbol.exists then
1661+
val sym = ref.symbol.asTerm
1662+
elems.get(sym) match
1663+
case null =>
1664+
elems.put(sym, pre)
1665+
case prefix: Type =>
1666+
if !(prefix =:= pre) then elems.put(sym, pre :: prefix :: Nil)
1667+
case prefixes: List[Type] =>
1668+
if !prefixes.exists(_ =:= pre) then elems.put(sym, pre :: prefixes)
16681669

16691670
def ++= (that: TermRefSet): Unit =
16701671
if !that.isEmpty then that.foreach(+=)

tests/neg/i9328.scala

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// fuzz test to avoid NoSymbol.owner
2+
type Id[T] = T match {
3+
case _ => T
4+
}
5+
6+
class Foo2[T <: Id[T]] // error // error
7+
8+
object Foo { // error
9+
object Foo { }
10+
Foo { }
11+
}
12+
implicit class Foo(a: Float) // error
13+
case class Foo()
14+
15+
case class Bar(
16+
} { ; // error
17+
object Bar { // error
18+
class Foo(a: Int) extends AnyVal
19+
Foo()
20+
}
21+
type Bar // error

0 commit comments

Comments
 (0)