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

Another is not a class type error when creating an anonymous subclass of an abstract class via new through a type alias #19745

Open
neko-kai opened this issue Feb 20, 2024 · 5 comments
Labels
backlog No work planned on this by the core team for the time being. itype:enhancement

Comments

@neko-kai
Copy link
Contributor

neko-kai commented Feb 20, 2024

Compiler version

3.4.0

Minimized code

https://scastie.scala-lang.org/gxYxc2GGSL2Kakv3xDQyKA

final abstract class ForcedRecompilationToken[T]
object ForcedRecompilationToken {
  implicit def default: ForcedRecompilationToken["abc"] = null
}

object x {
  abstract class GoodNoParens[T](implicit ev: ForcedRecompilationToken[T])
}
type BadNoParens[T] = x.GoodNoParens[T]

object App extends App {
  // error
  new BadNoParens {}

  // ok
  new BadNoParens() {}
  new x.GoodNoParens {}

  println("compiled")
}

Output

x.GoodNoParens is not a class type

Expectation

Same issue as in #18623, but this time it's when instantiating via new instead of declaring an object.

@neko-kai neko-kai added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 20, 2024
neko-kai added a commit to 7mind/izumi that referenced this issue Feb 21, 2024
@odersky odersky self-assigned this Feb 24, 2024
@odersky
Copy link
Contributor

odersky commented Feb 24, 2024

Since it looked similar #18623, I had a look at it. Unfortunately, here we see a completely different code path since this is a new {} expression. It will be quite messy to fix this. Maybe we should not even try.

@odersky odersky removed their assignment Feb 24, 2024
@odersky odersky added itype:enhancement backlog No work planned on this by the core team for the time being. and removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 26, 2024
@neko-kai
Copy link
Contributor Author

@odersky As with the previous issues in this series, this also affects export statements and makes them unreliable.

https://scastie.scala-lang.org/jn9DzwGoR4WW7wrFB4ERFg

final abstract class ForcedRecompilationToken[T]
object ForcedRecompilationToken {
  implicit def default: ForcedRecompilationToken["abc"] = null
}

object x {
  abstract class GoodNoParens[T](implicit ev: ForcedRecompilationToken[T])
}
export x.GoodNoParens as BadNoParens

object App extends App {
  // error
  new BadNoParens {}

  // ok
  new BadNoParens() {}
  new x.GoodNoParens {}

  println("compiled")
}

This worked correctly on Scala 2 and is still blocking me from porting existing library code to Scala 3...[1]

@odersky
Copy link
Contributor

odersky commented Feb 27, 2024

Can't you just write new BadNoParents() everywhere?

@neko-kai
Copy link
Contributor Author

@odersky Well, not really, in the real-world use case the type parameter, the implicit, the parens (that aren't even actually present in the class header either) are all implementation details that the user doesn't have to even know about. In worst case, I will have to remove the export - not force the user to write parentheses.

In the abstract case, I'm not sure export has to be leaky - especially in cases where type aliases worked correctly before, in Scala 2.

@Linyxus Linyxus closed this as completed in 1ef2574 Mar 2, 2024
@odersky odersky reopened this Mar 2, 2024
neko-kai added a commit to 7mind/izumi that referenced this issue Mar 7, 2024
neko-kai added a commit to 7mind/izumi that referenced this issue May 30, 2024
…Def,BootstrapPluginDef}` aliases on Scala 3
neko-kai added a commit to 7mind/izumi that referenced this issue May 30, 2024
* Revert "Disable recompilation trigger functionality on Scala 3 completely due to bug scala/scala3#15976"

This reverts commit 2ab8bf4.

* use random token again. Waiting on usability fix for scala/scala3#18623 before merge

* CI workaround for scala/scala3#19745

* Due to Scala 3 bug scala/scala3#19745 remove `distage.plugins.{PluginDef,BootstrapPluginDef}` aliases on Scala 3
@neko-kai
Copy link
Contributor Author

So far I had to remove type aliases / exports in our Scala 3 port because of this issue. Maybe this could be addressed at some point? It really breaks the export abstraction for classes if their constructors are used in a DSL.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backlog No work planned on this by the core team for the time being. itype:enhancement
Projects
None yet
Development

No branches or pull requests

2 participants