Skip to content

Fix #3352: Avoid widening method TermRefs in compatibility checks #3386

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 2 commits into from
Oct 26, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 9 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ object ProtoTypes {
val mbr = if (privateOK) tp1.member(name) else tp1.nonPrivateMember(name)
def qualifies(m: SingleDenotation) =
memberProto.isRef(defn.UnitClass) ||
compat.normalizedCompatible(m.info, memberProto)
compat.normalizedCompatible(NamedType(tp1, name, m), memberProto)
// Note: can't use `m.info` here because if `m` is a method, `m.info`
// loses knowledge about `m`'s default arguments.
mbr match { // hasAltWith inlined for performance
case mbr: SingleDenotation => mbr.exists && qualifies(mbr)
case _ => mbr hasAltWith qualifies
Expand Down Expand Up @@ -431,6 +433,7 @@ object ProtoTypes {
* - skips implicit parameters of methods and functions;
* if result type depends on implicit parameter, replace with fresh type dependent parameter.
* - converts non-dependent method types to the corresponding function types
* unless the expected type is an ApplyingProto or IgnoredProto.
* - dereferences parameterless method types
* - dereferences nullary method types provided the corresponding function type
* is not a subtype of the expected type.
Expand All @@ -451,8 +454,11 @@ object ProtoTypes {
else {
val rt = normalize(mt.resultType, pt)
pt match {
case pt: IgnoredProto => mt
case pt: ApplyingProto => mt.derivedLambdaType(mt.paramNames, mt.paramInfos, rt)
case pt: IgnoredProto =>
tp
case pt: ApplyingProto =>
if (rt eq mt.resultType) tp
else mt.derivedLambdaType(mt.paramNames, mt.paramInfos, rt)
case _ =>
val ft = defn.FunctionOf(mt.paramInfos, rt)
if (mt.paramInfos.nonEmpty || ft <:< pt) ft else rt
Expand Down
5 changes: 5 additions & 0 deletions tests/pending/neg/i3253.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Test.test

object Test {
def test = " " * 10
}