Skip to content

Commit

Permalink
SI-5900 Fix pattern inference regression
Browse files Browse the repository at this point in the history
This commit does not close SI-5900. It only addresses a regression
in 2.11 prereleases caused by SI-7886.

The fix for SI-7886 was incomplete (as shown by the last commit)
and incorrect (as shown by the regression in pos/t5900a.scala and
the fact it ended up inferring type parameters.)

I believe that the key to fixing this problem will be unifying
the inference of case class constructor patterns and extractor
patterns.

I've explored that idea:

  https://gist.github.com/retronym/7704153
  https://github.com/retronym/scala/compare/ticket/5900

But didn't quite get there.
  • Loading branch information
retronym authored and adriaanm committed Feb 13, 2014
1 parent b4e1a30 commit c956a27
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 17 deletions.
8 changes: 5 additions & 3 deletions src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,12 @@ trait PatternTypers {
* see test/files/../t5189*.scala
*/
private def convertToCaseConstructor(tree: Tree, caseClass: Symbol, ptIn: Type): Tree = {
def untrustworthyPt = (
// TODO SI-7886 / SI-5900 This is well intentioned but doesn't quite hit the nail on the head.
// For now, I've put it completely behind -Xstrict-inference.
val untrustworthyPt = settings.strictInference && (
ptIn =:= AnyTpe
|| ptIn =:= NothingTpe
|| settings.strictInference && ptIn.typeSymbol != caseClass
|| ptIn.typeSymbol != caseClass
)
val variantToSkolem = new VariantToSkolemMap
val caseClassType = tree.tpe.prefix memberType caseClass
Expand Down Expand Up @@ -371,4 +373,4 @@ trait PatternTypers {
}
}
}
}
}
2 changes: 1 addition & 1 deletion test/files/neg/t4818.check
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
t4818.scala:4: error: type mismatch;
found : Int(5)
required: A
required: Nothing
def f(x: Any) = x match { case Fn(f) => f(5) }
^
one error found
2 changes: 1 addition & 1 deletion test/files/neg/t5189.check
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
t5189.scala:3: error: type mismatch;
found : T => U
found : Nothing => Any
required: Any => Any
def f(x: Any): Any => Any = x match { case Foo(bar) => bar }
^
Expand Down
1 change: 1 addition & 0 deletions test/files/neg/t6680a.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xstrict-inference
12 changes: 6 additions & 6 deletions test/files/neg/t6829.check
Original file line number Diff line number Diff line change
Expand Up @@ -16,32 +16,32 @@ t6829.scala:49: error: not found: value nextState
val (s,a,s2) = (state,actions(agent),nextState)
^
t6829.scala:50: error: type mismatch;
found : s.type (with underlying type T1)
found : s.type (with underlying type Any)
required: _53.State where val _53: G
val r = rewards(agent).r(s,a,s2)
^
t6829.scala:50: error: type mismatch;
found : a.type (with underlying type T2)
found : a.type (with underlying type Any)
required: _53.Action where val _53: G
val r = rewards(agent).r(s,a,s2)
^
t6829.scala:50: error: type mismatch;
found : s2.type (with underlying type T3)
found : s2.type (with underlying type Any)
required: _53.State where val _53: G
val r = rewards(agent).r(s,a,s2)
^
t6829.scala:51: error: type mismatch;
found : s.type (with underlying type T1)
found : s.type (with underlying type Any)
required: _50.State
agent.learn(s,a,s2,r): G#Agent
^
t6829.scala:51: error: type mismatch;
found : a.type (with underlying type T2)
found : a.type (with underlying type Any)
required: _50.Action
agent.learn(s,a,s2,r): G#Agent
^
t6829.scala:51: error: type mismatch;
found : s2.type (with underlying type T3)
found : s2.type (with underlying type Any)
required: _50.State
agent.learn(s,a,s2,r): G#Agent
^
Expand Down
6 changes: 0 additions & 6 deletions test/files/neg/t7886.check

This file was deleted.

9 changes: 9 additions & 0 deletions test/files/pos/t5900a.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
case class Transition[S](x: S)

object C

object Test {
(??? : Any) match {
case Transition(C) =>
}
}
File renamed without changes.
File renamed without changes.

1 comment on commit c956a27

@scala-jenkins
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Job pr-scala failed for c956a27 Took 87 min. (ping @adriaanm) (results):


To retry exactly this commit, comment "PLS REBUILD/pr-scala@c956a27c3278b99d45676c268955a9e58a1ed15c" on PR 3523.
NOTE: New commits are rebuilt automatically as they appear. A forced rebuild is only necessary for transient failures.

Please sign in to comment.