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

Sould infix work on enum? #18933

Closed
nicolasstucki opened this issue Nov 15, 2023 · 8 comments · Fixed by #19010
Closed

Sould infix work on enum? #18933

nicolasstucki opened this issue Nov 15, 2023 · 8 comments · Fixed by #19010

Comments

@nicolasstucki
Copy link
Contributor

Compiler version

3.3

Minimized example

import language.future
enum Extends[A, B]:
  case Ev[B, A <: B]() extends (A Extends B)
3 |  case Ev[B, A <: B]() extends (A Extends B)
  |                                  ^^^^^^^
  |Alphanumeric type Extends is not declared infix; it should not be used as infix operator.
  |Instead, use prefix syntax Extends[...] or backticked identifier `Extends`.
  |The latter can be rewritten automatically under -rewrite -source future-migration.

but

infix enum Extends[A, B]:
  case Ev[B, A <: B]() extends (A Extends B)
1 |infix enum Extends[A, B]:
  |           ^^^^^^^
  |           Only access modifiers are allowed on enum definitions

Question

Should infix work on enum to mark it as an infix type?

@nicolasstucki
Copy link
Contributor Author

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Nov 15, 2023

I assume it should be allowed. @odersky is this the case?

@odersky
Copy link
Contributor

odersky commented Nov 15, 2023

I think we should allow it.

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 16, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 21, 2023
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Nov 22, 2023
@bishabosha
Copy link
Member

doesn't this need a SIP?

@sjrd
Copy link
Member

sjrd commented Nov 22, 2023

I don't think so. It looks to me light an oversight of the implementation. It's not like when we examined infix in SIP-2->3 that we said "let's add infix and allow to put on type definitions except enums".

@bishabosha
Copy link
Member

bishabosha commented Nov 23, 2023

the linked PR #19010 doesnt enable this, but should we also allow infix enum cases?

e.g.

import Expr.*

enum Expr[+A]:
  infix case to[A <: Int, B <: Int](min: A, max: B) extends Expr[Range]

extension [A <: Int](min: A)
  infix def to[B <: Int](max: B): A to B = Expr.to(min, max)

val foos: 1 to 23 = 1 to 23

@sjrd
Copy link
Member

sjrd commented Nov 23, 2023

They declare class types, so IMO yes.

@odersky
Copy link
Contributor

odersky commented Nov 23, 2023

Some enum cases declare class types, but not all. So we'd have to restrict it to those cases that actually do declare class types.

bishabosha added a commit that referenced this issue Nov 23, 2023
- [x] Add `compilationUnitInfo` to class symbols
- [x] Move `assocFile` into `CompilationUnitInfo`
- [x] Add tasty version to `CompilationUnitInfo`
- [x] Include #18925 to have test for `CompilationUnitInfo`
- [x] Add explicit nulls to `CompilationUnitInfo`

Fixes  #18933
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants