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

Under experimental.modularity, cannot extend a class inheriting a deferred given #21189

Closed
rjolly opened this issue Jul 13, 2024 · 3 comments · Fixed by #21206
Closed

Under experimental.modularity, cannot extend a class inheriting a deferred given #21189

rjolly opened this issue Jul 13, 2024 · 3 comments · Fixed by #21206
Assignees
Labels
area:experimental:modularity Issues related to the modularity extension. area:typer itype:bug
Milestone

Comments

@rjolly
Copy link
Contributor

rjolly commented Jul 13, 2024

Compiler version

3.5.0-RC3 with -source:future -language:experimental.modularity

Minimized code

trait Ord[T]

trait Sorted[T]:
  given Ord[T] as ord = compiletime.deferred

class SortedSet[T : Ord] extends Sorted[T]

class SortedSet2[T : Ord] extends SortedSet[T]

Output

^
error overriding given instance ord in class SortedSet of type Ord[T];
  given instance ord of type Ord[T] cannot override final member given instance ord in class SortedSet

Workaround

class SortedSet[T : Ord] extends Sorted[T]:
  override given ord: Ord[T] = summon
@rjolly rjolly added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 13, 2024
@rjolly rjolly changed the title Can't extend a class with a context bound parameter under experimental.modularity Under experimental.modularity, cannot extend a class inheriting a deferred given Jul 13, 2024
@bishabosha
Copy link
Member

bishabosha commented Jul 14, 2024

I can't reproduce the error, it compiles fine for me in 3.5.0-RC3 - maybe you oversimplified the code?

I tried to make the given final but still no error

@rjolly
Copy link
Contributor Author

rjolly commented Jul 14, 2024

Yes, sorry, you have to actually have several source files:
Ord.scala

trait Ord[T]

Sorted.scala

trait Sorted[T]:
  given Ord[T] as ord = compiletime.deferred

SortedSet.scala

class SortedSet[T : Ord] extends Sorted[T]

And (as unbelievable as it is) this last one needs to not contain the above as prefix : MySortedSet.scala

class MySortedSet[T : Ord] extends SortedSet[T]

(MySortedSet instead of SortedSet2)

@KacperFKorban
Copy link
Member

I managed to minimize it into a single file, but the order of declarations is important. Or at least it's important for MySortedSet to be declared before SortedSet.

//> using scala 3.nightly
//> using options -source:future -language:experimental.modularity

class MySortedSet[T : Ord] extends SortedSet[T]

trait Ord[T]

trait Sorted[T]:
  given Ord[T] as ord = compiletime.deferred

open class SortedSet[T : Ord] extends Sorted[T]

@KacperFKorban KacperFKorban self-assigned this Jul 16, 2024
@KacperFKorban KacperFKorban added area:typer area:experimental:modularity Issues related to the modularity extension. and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 16, 2024
odersky added a commit that referenced this issue Aug 1, 2024
…mplement it (#21206)

It should be possible to extend a class that inherits a deferred given,
so a generated given implementation should not be final.

closes #21189
@WojciechMazur WojciechMazur added this to the 3.5.2 milestone Oct 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:experimental:modularity Issues related to the modularity extension. area:typer itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants