Skip to content

Abstract type bound of type member is forgotten? #4884

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

Closed
kory33 opened this issue Aug 1, 2018 · 1 comment
Closed

Abstract type bound of type member is forgotten? #4884

kory33 opened this issue Aug 1, 2018 · 1 comment

Comments

@kory33
Copy link

kory33 commented Aug 1, 2018

object Test {
  trait A
  trait TestConstructor1 { type F[_ <: A] }
  trait TestConstructor2[D] { type F[_ <: D] }

  val v1: TestConstructor1 => Unit = { f =>
    type P[a <: A] = f.F[a] // OK
  }

  val v2: TestConstructor2[A] => Unit = { f =>
    type P[a <: A] = f.F[a] // Error! Type argument a does not conform to upper bound D
  }
}

This compiles in Scala 2.12.1 and does not compile in Dotty 0.8.0. Just reporting this but I might have overlooked some dropped features.

@Blaisorblade
Copy link
Contributor

The code should indeed compile. FWIW you probably want to use the latest RC, but this code still fails on latest master (429c1f2).

Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 4, 2018
In this code we fetch the type parameter bounds from the definition, so we must
substitute their definition using `asSeenFrom` with the correct prefix.

The correct prefix is however hard to find: `TypeApplications.typeParams` finds
a `self: TypeRefs` (after however many steps), the correct prefix is
`self.prefix`.

In fact, a compositional typing rule would obtain the bounds from the type (or,
well, kind) of the type constructor; that would avoid the need for using
`asSeenFrom`. We only have a way to obtain such a kind for `NamedType` (where we
can take the `info`). That might be enough, but there might be another way to
fix this.
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 7, 2018
odersky added a commit to dotty-staging/dotty that referenced this issue Aug 7, 2018
 - Type parameters of hk lambdas depend on prefix, can't be computed
   from symbol if prefix is non-trivial
 - Parameter bounds of such type parameters are already computed, so
   can be retrieved with paramInfo. The doc comment of paramInfoAsSeenFrom
   indicates this, but the implementation did something different.
 - Typer and Checking need to call paramInfoAsSeenFrom to get the right
   bounds in general.

This also fixes scala#4884.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 7, 2018
In this code we fetch the type parameter bounds from the definition, so we must
substitute their definition using `asSeenFrom` with the correct prefix.

The correct prefix is however hard to find: `TypeApplications.typeParams` finds
a `self: TypeRefs` (after however many steps), the correct prefix is
`self.prefix`.

In fact, a compositional typing rule would obtain the bounds from the type (or,
well, kind) of the type constructor; that would avoid the need for using
`asSeenFrom`. We only have a way to obtain such a kind for `NamedType` (where we
can take the `info`). However, that seems enough.
Blaisorblade added a commit to dotty-staging/dotty that referenced this issue Aug 7, 2018
In this code we fetch the type parameter bounds from the definition, so we must
substitute their definition using `asSeenFrom` with the correct prefix.

The correct prefix is however hard to find: `TypeApplications.typeParams` finds
a `self: TypeRefs` (after however many steps), the correct prefix is
`self.prefix`.

In fact, a compositional typing rule would obtain the bounds from the type (or,
well, kind) of the type constructor; that would avoid the need for using
`asSeenFrom`. We only have a way to obtain such a kind for `NamedType` (where we
can take the `info`). However, that seems enough.
allanrenucci pushed a commit to dotty-staging/dotty that referenced this issue Aug 8, 2018
 - Type parameters of hk lambdas depend on prefix, can't be computed
   from symbol if prefix is non-trivial
 - Parameter bounds of such type parameters are already computed, so
   can be retrieved with paramInfo. The doc comment of paramInfoAsSeenFrom
   indicates this, but the implementation did something different.
 - Typer and Checking need to call paramInfoAsSeenFrom to get the right
   bounds in general.

This also fixes scala#4884.
@odersky odersky closed this as completed in 3739026 Aug 8, 2018
odersky added a commit that referenced this issue Aug 8, 2018
Fix #4884: Fix handling of bounds of type lambdas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants