Skip to content
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

Spurious 'type mismatch': a type is reduced to Any where a proper subtype would be sound #95

Closed
scabug opened this issue Sep 14, 2007 · 4 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 14, 2007

The source code below shows the minimal context that I've been able to extract that demonstrates the problem and is compilable on its own. Essentially, the problem is that a type is upper-bounded too aggressively in a match-in-match context such that an expression is considered as having type Any where it should have had type Output, and hence the program is rejected as having a type mismatch where it could actually have been accepted as type safe.

// scalac 2.6.0-final produces an error message for this at '=> Success(so)':
// type mismatch, found: Any, required: Output, but so:Output _is_ knowable

class ParseResult[+T]
case class Success[+T](t: T) extends ParseResult[T]

abstract class Nonterminal[Output] {

  type SubNonterminal = Nonterminal[T] forSome { type T <: Output }

  def parse: ParseResult[Output]

  def parse1(nts: List[SubNonterminal]): ParseResult[Output] =
    nts match {
      case nt::nts => nt.parse match { case Success(so) => Success(so) }
      case Nil => throw new Error
    }
}
@scabug
Copy link
Author

scabug commented Sep 14, 2007

Imported From: https://issues.scala-lang.org/browse/SI-95?orig=1
Reporter: Erik Ernst (ernst)

@scabug
Copy link
Author

scabug commented Jan 14, 2009

@odersky said:
Milestone postponed deleted

@scabug
Copy link
Author

scabug commented Feb 12, 2009

@paulp said:
For future reference, if you instead declare parse1 like this:

  def parse1[T <: SubNonterminal](nts: List[T]): ParseResult[Output] =
  // def parse1(nts: List[SubNonterminal]): ParseResult[Output] =

then it compiles. Of course those should be equivalent, but as we can see they're not (maybe monomorphic vs. polymorphic code paths?)

@scabug
Copy link
Author

scabug commented Jul 2, 2010

@paulp said:
(In r22467) Test cases close #13, #95. No review.

(That's right, multiple two digit tickets.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants