-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Regression(?) in kubukoz/slick-effect - type projections in separate compilation runs #22581
Comments
|
@jchyb Are you sure |
You are right, it also errors out with a class. What bothered me mainly was the fact that in 3.6.3 and earlier this error did appear, but only if both the type definition and method call were in the same compilation run, which led to to think the error might be correct (although, If I recall correctly, the compiler should just inform us directly if an illegal type projection is used). |
Same issue in case class Test()(implicit proof: JdbcBackend#StreamingContext <:< JdbcBackend#Context)
class JdbcBackend:
type Context = JdbcActionContext
type StreamingContext = JdbcStreamingActionContext
class JdbcStreamingActionContext extends JdbcActionContext
class JdbcActionContext
val _ = new Test() |
I tried to further minimized and got the following single-file reproduction. Is that still the same problem? // a.scala
package slickeffect
def fromDatabase(dbF: JdbcBackend#Database): Unit = ???
class JdbcBackend:
type Database = DatabaseFactory
val Database: DatabaseFactory = ???
class DatabaseFactory
@main def main =
val backend = JdbcBackend()
fromDatabase(new backend.Database())
|
@mbovel This seems like another issue: the reported problem is a regression from 3.6.3, while your snippet doesn't seem to compile in any version of scala 3. Just to double-check I rewrote it to something scala-2-compatible: package slickeffect
class JdbcBackend {
type Database = DatabaseFactory
val Database: DatabaseFactory = ???
class DatabaseFactory
}
object App {
def fromDatabase(dbF: JdbcBackend#Database): Unit = ???
def main(args: Array[String]) = {
val backend = new JdbcBackend()
fromDatabase(new backend.Database())
}
} This compiles in scala 2.13.16, but doesn't in any version of scala 3 |
Thanks @prolativ for trying with other versions! Given that my singe-file reproduction doesn't compile in any version of Scala 3, I don't see why the version split in two compilation units should compile. I agree with @jchyb's analysis: maybe this should never be valid and the compiler should inform us that an illegal type projection is used. |
cc @odersky |
Running my single-file reproduction above with
|
The example compiles OK if I replace package slickeffect
class JdbcBackend {
type Database = DatabaseFactory
val Database: DatabaseFactory = ???
class DatabaseFactory
}
object App {
def fromDatabase(dbF: JdbcBackend#DatabaseFactory): Unit = ???
def main(args: Array[String]) = {
val backend = new JdbcBackend()
fromDatabase(new backend.Database())
}
} So it looks like this should compile, since type aliases should not matter for subtyping checks. |
In fact, on closer inspection, it should not compile.
This shows again how slippery and fragile type projections are. Maybe we should restrict them further, and only allow |
Since the originally reported problem has the same underlying configuration as @mbovel's minimization, I guess it worked by accident before and rightly should not work anymore. Easy workaround: Don't use type aliases in type projection, expand to the original class instead. |
cc @kubukoz |
OpenCB: https://github.com/VirtusLab/community-build3/actions/runs/13209505213/job/36881103468
Compiler version
Working(?): 3.6.3
Broken(?): 3.6.4-RC1
Minimized code
Has to be split into 2 modules/separate compilation runs, for simplicity let's use scala-cli:
main.scala
main.test.scala
scala-cli test main.scala main.test.scala
Output
In 3.6.4-RC1 and before - no error.
In 3.7.0-RC1-bin-20250207-d60a914-NIGHTLY:
Expectation
Not sure. Type projections like this should be unsupported in scala 3, and this error can also appear in previous compiler versions if both files are a part of the same compilation run. This leads me to believe this is more of a bugfix then regression, but I still wanted to log somewhere the OpenCB error and minimization.
The text was updated successfully, but these errors were encountered: