Skip to content

Fix hasKnownMembers #14762

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -157,28 +157,35 @@ object ProtoTypes {
abstract case class SelectionProto(name: Name, memberProto: Type, compat: Compatibility, privateOK: Boolean)
extends CachedProxyType with ProtoType with ValueTypeOrProto {

/** Is the set of members of this type unknown? This is the case if:
* 1. The type has Nothing or Wildcard as a prefix or underlying type
* 2. The type has an uninstantiated TypeVar as a prefix or underlying type,
* or as an upper bound of a prefix or underlying type.
/** Is the set of members of this type unknown, in the sense that we
* cannot compute a non-trivial upper approximation? This is the case if:
* 1. The type has Nothing or Wildcard as a prefix or underlying type
* 2. The type is an abstract type with a lower bound that has a unknown
* members and an upper bound that is both provisional and has unknown members.
* 3. The type is an uninstiated type var with a lower that has unknown members.
* 4. Type proxies have unknown members if their super types do
*/
private def hasUnknownMembers(tp: Type)(using Context): Boolean = tp match {
case tp: TypeVar => !tp.isInstantiated
private def hasUnknownMembers(tp: Type)(using Context): Boolean = tp match
case tp: WildcardType => true
case NoType => true
case tp: TypeRef =>
val sym = tp.symbol
sym == defn.NothingClass ||
!sym.isStatic && {
hasUnknownMembers(tp.prefix) || {
val bound = tp.info.hiBound
bound.isProvisional && hasUnknownMembers(bound)
}
}
sym == defn.NothingClass
|| !sym.isClass
&& !sym.isStatic
&& {
hasUnknownMembers(tp.prefix)
|| { val bound = tp.info.hiBound
bound.isProvisional && hasUnknownMembers(bound)
} && hasUnknownMembers(tp.info.loBound)
}
case tp: TypeVar if !tp.isInstantiated =>
hasUnknownMembers(TypeComparer.bounds(tp.origin).lo)
case tp: AppliedType => hasUnknownMembers(tp.tycon) || hasUnknownMembers(tp.superType)
case tp: TypeProxy => hasUnknownMembers(tp.superType)
// It woukd make sense to also include And/OrTypes, but that leads to
// infinite recursions, as observed for instance for t2399.scala.
case _ => false
}

override def isMatchedBy(tp1: Type, keepConstraint: Boolean)(using Context): Boolean =
name == nme.WILDCARD || hasUnknownMembers(tp1) ||
Expand Down
9 changes: 0 additions & 9 deletions tests/neg/i13900.scala

This file was deleted.

14 changes: 14 additions & 0 deletions tests/pos/i13900.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import compiletime.ops.int.Max
import scala.annotation.targetName
opaque type Inlined[T] = T
object Inlined:
extension [T](inlined: Inlined[T]) def value: T = inlined
inline given fromValue[T <: Singleton]: Conversion[T, Inlined[T]] =
value => value
@targetName("fromValueWide")
given fromValue[Wide]: Conversion[Wide, Inlined[Wide]] = value => value

def forced[T](value: Any): Inlined[T] = value.asInstanceOf[T]
extension [T <: Int](lhs: Inlined[T])
def max[R <: Int](rhs: Inlined[R]) =
forced[Max[T, R]](lhs.value max rhs.value)