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

Separate compilation and subtype checking of HK types #4167

Closed
allanrenucci opened this issue Mar 23, 2018 · 0 comments
Closed

Separate compilation and subtype checking of HK types #4167

allanrenucci opened this issue Mar 23, 2018 · 0 comments

Comments

@allanrenucci
Copy link
Contributor

In a file collections.scala:

package collection

trait Seq[+A] extends SeqOps[A, Seq, Seq[A]]
trait SeqOps[+A, +CC[_], +C] extends Any

package immutable {
  trait Seq[+A] extends collection.Seq[A] with SeqOps[A, Seq, Seq[A]]
  trait SeqOps[+A, +CC[_], +C] extends collection.SeqOps[A, CC, C]
}

class StringOps extends collection.SeqOps[Char, immutable.Seq, String]

In a file Test.scala:

package collection

object Test {
  type AnyConstr[X] = Any
  val test: SeqOps[Char, AnyConstr, _] = null.asInstanceOf[StringOps]
}
$ dotc -d out collections.scala
$ dotc -d out -classpath out Test.scala -explain-types
-- [E007] Type Mismatch Error: tests/allan/Test.scala:5:58 ---------------------
5 |  val test: SeqOps[Char, AnyConstr, _] = null.asInstanceOf[StringOps]
  |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |found:    collection.StringOps
  |required: collection.SeqOps[Char, collection.Test.AnyConstr, _]
  |
  |
  |Constraint(
  | uninstVars = ;
  | constrained types = 
  | bounds = 
  | ordering = 
  |)
  |Subtype trace:
  |  ==> collection.StringOps <:< collection.SeqOps[Char, collection.Test.AnyConstr, _]  
  |    ==> collection.SeqOps[Char, collection.immutable.Seq, String] <:< collection.SeqOps[Char, collection.Test.AnyConstr, _] LoApprox 
  |      ==> collection.type <:< collection.type(collection)  
  |      <== collection.type <:< collection.type(collection)   = true
  |      ==> Char <:< Char  
  |        ==> scala.type <:< scala.type  
  |        <== scala.type <:< scala.type   = true
  |      <== Char <:< Char   = true
  |      ==> collection.immutable.Seq <:< collection.Test.AnyConstr  
  |      <== collection.immutable.Seq <:< collection.Test.AnyConstr   = false
  |    <== collection.SeqOps[Char, collection.immutable.Seq, String] <:< collection.SeqOps[Char, collection.Test.AnyConstr, _] LoApprox  = false
  |  <== collection.StringOps <:< collection.SeqOps[Char, collection.Test.AnyConstr, _]   = false
one error found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants