-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix/dependent methods #694
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
Changes from 6 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
890b8a4
Avoid follow-on errors after implicit argument errors.
odersky ffac03a
Handle normalization of implicit dependent methods.
odersky 5395414
Drop redundant adapt.
odersky bb90c84
setNewTyperState -> setExploreTyperState when computing shadoing impl…
odersky f3f75ca
Sharpen prototypes of implicit methods.
odersky 1e9ffd4
Add test from pending.
odersky e984e23
Cleanups
odersky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1279,10 +1279,37 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
} | ||
} | ||
|
||
/** If `tp` is a TypeVar which is fully constrained (i.e. its upper bound `hi` conforms | ||
* to its lower bound `lo`), replace `tp` by `hi`. This is necessary to | ||
* keep the right constraints for some implicit search problems. The paradigmatic case | ||
* is `implicitNums.scala`. Without the healing done in `followAlias`, we cannot infer | ||
* implicitly[_3], where _2 is the typelevel number 3. The problem here is that if a | ||
* prototype is, say, Succ[Succ[Zero]], we can infer that it's argument type is Succ[Zero]. | ||
* But if the prototype is N? >: Succ[Succ[Zero]] <: Succ[Succ[Zero]], the same | ||
* decomposition does not work - we'd get a N?#M where M is the element type name of Succ | ||
* instead. | ||
*/ | ||
def followAlias(tp: Type)(implicit ctx: Context): Type = { | ||
val constraint = ctx.typerState.constraint | ||
def inst(tp: Type): Type = tp match { | ||
case TypeBounds(lo, hi) => | ||
if ((lo eq hi) || (hi <:< lo)(ctx.fresh.setExploreTyperState)) inst(lo) else NoType | ||
case tp: PolyParam => | ||
var tvar1 = constraint.typeVarOfParam(tp) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be a |
||
if (tvar1.exists) tvar1 else tp | ||
case _ => tp | ||
} | ||
tp match { | ||
case tp: TypeVar if constraint.contains(tp) => inst(constraint.entry(tp.origin)) | ||
case _ => tp | ||
} | ||
} | ||
|
||
def adaptNoArgs(wtp: Type): Tree = wtp match { | ||
case wtp: ExprType => | ||
adaptInterpolated(tree.withType(wtp.resultType), pt, original) | ||
case wtp: ImplicitMethodType if constrainResult(wtp, pt) => | ||
case wtp: ImplicitMethodType if constrainResult(wtp, followAlias(pt)) => | ||
val constr = ctx.typerState.constraint | ||
def addImplicitArgs = { | ||
def implicitArgError(msg: => String): Tree = { | ||
ctx.error(msg, tree.pos.endPos) | ||
|
@@ -1292,14 +1319,15 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |
def where = d"parameter $pname of $methodStr" | ||
inferImplicit(formal, EmptyTree, tree.pos.endPos) match { | ||
case SearchSuccess(arg, _, _) => | ||
adapt(arg, formal) | ||
arg | ||
case ambi: AmbiguousImplicits => | ||
implicitArgError(s"ambiguous implicits: ${ambi.explanation} of $where") | ||
case failure: SearchFailure => | ||
implicitArgError(d"no implicit argument of type $formal found for $where" + failure.postscript) | ||
} | ||
} | ||
adapt(tpd.Apply(tree, args), pt) | ||
if (args.exists(_.isEmpty)) { assert(constr eq ctx.typerState.constraint); tree } | ||
else adapt(tpd.Apply(tree, args), pt) | ||
} | ||
if ((pt eq WildcardType) || original.isEmpty) addImplicitArgs | ||
else | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
object Test { | ||
|
||
trait Number | ||
trait Zero extends Number | ||
trait Succ[N <: Number](n: N) extends Number | ||
|
||
implicit def succ[N <: Number](implicit n: N): Succ[N] = new Succ[N](n) {} | ||
implicit def zero: Zero = new Zero{} | ||
|
||
implicitly[Zero] | ||
implicitly[Succ[Zero]] | ||
implicitly[Succ[Succ[Zero]]] | ||
implicitly[Succ[Succ[Succ[Zero]]]] | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a comment explaining why
NoType
instead oftp
makes sense here?