aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Applications.scala7
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Namer.scala2
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Typer.scala50
3 files changed, 26 insertions, 33 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala
index c4d3e2292..7e17abbcd 100644
--- a/compiler/src/dotty/tools/dotc/typer/Applications.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala
@@ -48,9 +48,6 @@ object Applications {
ref.info.widenExpr.dealias
}
- def canProductMatch(tp: Type)(implicit ctx: Context) =
- extractorMemberType(tp, nme._1).exists
-
/** Does `tp` fit the "product match" conditions as an unapply result type
* for a pattern with `numArgs` subpatterns?
* This is the case of `tp` has members `_1` to `_N` where `N == numArgs`.
@@ -72,7 +69,7 @@ object Applications {
}
def productArity(tp: Type)(implicit ctx: Context) =
- if (canProductMatch(tp)) productSelectorTypes(tp).size else -1
+ if (defn.isProductSubType(tp)) productSelectorTypes(tp).size else -1
def productSelectors(tp: Type)(implicit ctx: Context): List[Symbol] = {
val sels = for (n <- Iterator.from(0)) yield tp.member(nme.selectorName(n)).symbol
@@ -114,7 +111,7 @@ object Applications {
getUnapplySelectors(getTp, args, pos)
else if (unapplyResult isRef defn.BooleanClass)
Nil
- else if (canProductMatch(unapplyResult))
+ else if (defn.isProductSubType(unapplyResult))
productSelectorTypes(unapplyResult)
// this will cause a "wrong number of arguments in pattern" error later on,
// which is better than the message in `fail`.
diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala
index 19b6dfa71..da9f9f6ac 100644
--- a/compiler/src/dotty/tools/dotc/typer/Namer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala
@@ -843,7 +843,7 @@ class Namer { typer: Typer =>
val targs1 = targs map (typedAheadType(_))
val ptype = typedAheadType(tpt).tpe appliedTo targs1.tpes
if (ptype.typeParams.isEmpty) ptype
- else typedAheadExpr(parent).tpe
+ else fullyDefinedType(typedAheadExpr(parent).tpe, "class parent", parent.pos)
}
/* Check parent type tree `parent` for the following well-formedness conditions:
diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala
index ba55dfe30..02538671e 100644
--- a/compiler/src/dotty/tools/dotc/typer/Typer.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala
@@ -179,6 +179,20 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
previous
}
+ def selection(imp: ImportInfo, name: Name) =
+ if (imp.sym.isCompleting) {
+ ctx.warning(i"cyclic ${imp.sym}, ignored", tree.pos)
+ NoType
+ } else if (unimported.nonEmpty && unimported.contains(imp.site.termSymbol))
+ NoType
+ else {
+ val pre = imp.site
+ val denot = pre.member(name).accessibleFrom(pre)(refctx)
+ // Pass refctx so that any errors are reported in the context of the
+ // reference instead of the
+ if (reallyExists(denot)) pre.select(name, denot) else NoType
+ }
+
/** The type representing a named import with enclosing name when imported
* from given `site` and `selectors`.
*/
@@ -194,25 +208,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
found
}
- def selection(name: Name) =
- if (imp.sym.isCompleting) {
- ctx.warning(i"cyclic ${imp.sym}, ignored", tree.pos)
- NoType
- }
- else if (unimported.nonEmpty && unimported.contains(imp.site.termSymbol))
- NoType
- else {
- // Pass refctx so that any errors are reported in the context of the
- // reference instead of the
- checkUnambiguous(selectionType(imp.site, name, tree.pos)(refctx))
- }
+ def unambiguousSelection(name: Name) =
+ checkUnambiguous(selection(imp, name))
selector match {
case Thicket(fromId :: Ident(Name) :: _) =>
val Ident(from) = fromId
- selection(if (name.isTypeName) from.toTypeName else from)
+ unambiguousSelection(if (name.isTypeName) from.toTypeName else from)
case Ident(Name) =>
- selection(name)
+ unambiguousSelection(name)
case _ =>
recur(rest)
}
@@ -225,18 +229,10 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
/** The type representing a wildcard import with enclosing name when imported
* from given import info
*/
- def wildImportRef(imp: ImportInfo)(implicit ctx: Context): Type = {
- if (imp.isWildcardImport) {
- val pre = imp.site
- if (!unimported.contains(pre.termSymbol) &&
- !imp.excluded.contains(name.toTermName) &&
- name != nme.CONSTRUCTOR) {
- val denot = pre.member(name).accessibleFrom(pre)(refctx)
- if (reallyExists(denot)) return pre.select(name, denot)
- }
- }
- NoType
- }
+ def wildImportRef(imp: ImportInfo)(implicit ctx: Context): Type =
+ if (imp.isWildcardImport && !imp.excluded.contains(name.toTermName) && name != nme.CONSTRUCTOR)
+ selection(imp, name)
+ else NoType
/** Is (some alternative of) the given predenotation `denot`
* defined in current compilation unit?
@@ -763,7 +759,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
/** Is `formal` a product type which is elementwise compatible with `params`? */
def ptIsCorrectProduct(formal: Type) = {
isFullyDefined(formal, ForceDegree.noBottom) &&
- Applications.canProductMatch(formal) &&
+ defn.isProductSubType(formal) &&
Applications.productSelectorTypes(formal).corresponds(params) {
(argType, param) =>
param.tpt.isEmpty || argType <:< typedAheadType(param.tpt).tpe