Skip to content

Fix #2404: Fixes to make collections strawman compile, take 3 #2408

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 5 commits into from
May 11, 2017
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
30 changes: 23 additions & 7 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -310,12 +310,28 @@ object Denotations {
}
case tp1: MethodOrPoly =>
tp2 match {
case tp2: MethodOrPoly
if ctx.typeComparer.matchingParams(tp1, tp2) &&
tp1.isImplicit == tp2.isImplicit =>
tp1.derivedLambdaType(
mergeParamNames(tp1, tp2), tp1.paramInfos,
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
case tp2: MethodOrPoly =>
// Two remedial strategies:
//
// 1. Prefer method types over poly types. This is necessary to handle
// overloaded definitions like the following
//
// def ++ [B >: A](xs: C[B]): D[B]
// def ++ (xs: C[A]): D[A]
//
// (Code like this is found in the collection strawman)
//
// 2. In the case of two method types or two polytypes with matching
// parameters and implicit status, merge corresppnding parameter
// and result types.
if (tp1.isInstanceOf[PolyType] && tp2.isInstanceOf[MethodType]) tp2
else if (tp2.isInstanceOf[PolyType] && tp1.isInstanceOf[MethodType]) tp1
else if (ctx.typeComparer.matchingParams(tp1, tp2) &&
tp1.isImplicit == tp2.isImplicit)
tp1.derivedLambdaType(
mergeParamNames(tp1, tp2), tp1.paramInfos,
infoMeet(tp1.resultType, tp2.resultType.subst(tp2, tp1)))
else mergeConflict(tp1, tp2)
case _ =>
mergeConflict(tp1, tp2)
}
Expand Down Expand Up @@ -553,7 +569,7 @@ object Denotations {
if (sd1.exists)
if (sd2.exists)
if (isDoubleDef(denot1.symbol, denot2.symbol)) doubleDefError(denot1, denot2)
else throw new TypeError(s"failure to disambiguate overloaded reference $this")
else throw new TypeError(i"failure to disambiguate overloaded reference at $this")
else sd1
else sd2
}
Expand Down
16 changes: 15 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Signature.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package dotty.tools.dotc
package core

import Names._, Types._, Contexts._, StdNames._
import Names._, Types._, Contexts._, StdNames._, Decorators._
import TypeErasure.sigName

import scala.annotation.tailrec
Expand Down Expand Up @@ -49,6 +49,20 @@ case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
loop(this.paramsSig, that.paramsSig)
}

/** `that` signature, but keeping all corresponding parts of `this` signature. */
final def updateWith(that: Signature): Signature = {
def update(name1: TypeName, name2: TypeName): TypeName =
if (consistent(name1, name2)) name1 else name2
if (this == that) this
else if (!this.paramsSig.hasSameLengthAs(that.paramsSig)) that
else {
val mapped = Signature(
this.paramsSig.zipWithConserve(that.paramsSig)(update),
update(this.resSig, that.resSig))
if (mapped == this) this else mapped
}
}

/** The degree to which this signature matches `that`.
* If parameter names are consistent and result types names match (i.e. they are the same
* or one is a wildcard), the result is `FullMatch`.
Expand Down
14 changes: 12 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1867,8 +1867,18 @@ object Types {
}
else candidate

override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef =
fixDenot(TermRef.withSig(prefix, name, sig), prefix)
override def newLikeThis(prefix: Type)(implicit ctx: Context): TermRef = {
// If symbol exists, the new signature is the symbol's signature as seen
// from the new prefix, modulo consistency
val newSig =
if (sig == Signature.NotAMethod || !symbol.exists)
sig
else
sig.updateWith(symbol.info.asSeenFrom(prefix, symbol.owner).signature)
if (newSig ne sig)
core.println(i"sig change at ${ctx.phase} for $this, pre = $prefix, sig: $sig --> $newSig")
fixDenot(TermRef.withSig(prefix, name, newSig), prefix)
}

override def shadowed(implicit ctx: Context): NamedType =
fixDenot(TermRef.withSig(prefix, name.derived(ShadowedName), sig), prefix)
Expand Down
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/ErrorReporting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ object ErrorReporting {

def exprStr(tree: Tree): String = refStr(tree.tpe)

def takesNoParamsStr(tree: Tree, kind: String) =
if (tree.tpe.widen.exists)
i"${exprStr(tree)} does not take ${kind}parameters"
else
i"undefined: $tree # ${tree.uniqueId}: ${tree.tpe.toString}"

def patternConstrStr(tree: Tree): String = ???

def typeMismatch(tree: Tree, pt: Type, implicitFailure: SearchFailure = NoImplicitMatches): Tree =
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ trait TypeAssigner {
else
errorType(i"wrong number of arguments for $fntpe: ${fn.tpe}, expected: ${fntpe.paramInfos.length}, found: ${args.length}", tree.pos)
case t =>
errorType(i"${err.exprStr(fn)} does not take parameters", tree.pos)
errorType(err.takesNoParamsStr(fn, ""), tree.pos)
}
tree.withType(ownType)
}
Expand Down Expand Up @@ -396,7 +396,7 @@ trait TypeAssigner {
else wrongNumberOfTypeArgs(fn.tpe, pt.typeParams, args, tree.pos)
}
case _ =>
errorType(i"${err.exprStr(fn)} does not take type parameters", tree.pos)
errorType(err.takesNoParamsStr(fn, "type "), tree.pos)
}

tree.withType(ownType)
Expand Down