Skip to content

Spurious is not a class type error when inheriting a class without call parentheses() through a type alias #18623

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
neko-kai opened this issue Sep 29, 2023 · 4 comments · Fixed by #18849

Comments

@neko-kai
Copy link
Contributor

Compiler version

3.3.1

Minimized code

https://scastie.scala-lang.org/1OfTRArhRuKz5Kq59dUcHg

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

class GoodNoParens[T](implicit ev: ForcedRecompilationToken[T])
type BadNoParens[T] = GoodNoParens[T]

// error
object A extends BadNoParens

// ok
object B extends BadNoParens()
object C extends GoodNoParens

object App extends App {
  println("compiled")
}

Output

GoodNoParens is not a class type

Expectation

Similar situation as in #15976, but this time merely using a type alias to refer to the class breaks the fix for the aforementioned issue and causes a spurious 'not a class type' error.

@neko-kai neko-kai added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Sep 29, 2023
@odersky
Copy link
Contributor

odersky commented Oct 1, 2023

I think this is as it should be. BadNoParens is a higher kinded type, which is not a legal parent. BadNoParens() is a call to a constructor with inferred type parameters. GoodNoParens is a class type for which special rules apply (i.e. we infer parameters regardless).

I don't really see a strong reason for changing these rules.

@neko-kai
Copy link
Contributor Author

neko-kai commented Oct 1, 2023

@odersky BadNoParens is an alias to GoodNoParens, I believe that using it should not be materially different from using GoodNoParens directly, when at all possible. Otherwise some concepts, such as exports, stop working correctly. This bug also reproduces when using an export instead of a type alias - https://scastie.scala-lang.org/veWopnkESKO8aCdUPm352Q

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

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

// error
object A extends BadNoParens

// ok
object B extends BadNoParens()
object C extends x.GoodNoParens

object App extends App {
  println("compiled")
}

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

@dwijnand dwijnand added area:typer and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Oct 2, 2023
@odersky odersky self-assigned this Nov 5, 2023
@odersky
Copy link
Contributor

odersky commented Nov 5, 2023

OK, trying a fix...

odersky added a commit to dotty-staging/dotty that referenced this issue Nov 5, 2023
When typing parent types as constructors with implicitly added `()` arguments,
also admit alias types that become classes after eta-collapsing.

Fixes scala#18623
odersky added a commit to dotty-staging/dotty that referenced this issue Nov 5, 2023
When typing parent types as constructors with implicitly added `()` arguments,
also admit alias types that become classes after eta-collapsing.

Fixes scala#18623
odersky added a commit that referenced this issue Nov 6, 2023
When typing parent types as constructors with implicitly added `()`
arguments, also admit alias types that become classes after
eta-collapsing.

Fixes #18623
@neko-kai
Copy link
Contributor Author

neko-kai commented Nov 6, 2023

@odersky Thank you! 🙏

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
* 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
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.

3 participants