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

implicit members inconsistent support in structural types #9085

Closed
scabug opened this issue Jan 14, 2015 · 4 comments
Closed

implicit members inconsistent support in structural types #9085

scabug opened this issue Jan 14, 2015 · 4 comments

Comments

@scabug
Copy link

scabug commented Jan 14, 2015

Can't even parse that:

scala> type Foo = AnyRef { implicit val fooMsg: String }
<console>:1: error: illegal start of declaration
       type Foo = AnyRef { implicit val fooMsg: String }

But can do this (pay attention for the inferred structural type):

scala> val a = new { implicit val fooMsg: String = "a" }
a: AnyRef{implicit val fooMsg: String} = $anon$1@7b7b04e9

So, AnyRef{implicit val fooMsg: String} seems to be very confusing for the user especially as it can't even be parsed

As it has no actual effect:

scala> var b = a
b: AnyRef{implicit val fooMsg: String} = $anon$1@7b7b04e9

scala> b = new { implicit val fooMsg: String = "v" }
b: AnyRef{implicit val fooMsg: String} = $anon$1@7c8adf94

scala> b = new { val fooMsg: String = "v" } // shoud throw an error if check
b: AnyRef{implicit val fooMsg: String} = $anon$1@30cff762

scala> b = new { val fooMsgg: String = "v" }
<console>:9: error: type mismatch;
 found   : AnyRef{val fooMsgg: String; val fooMsgg: String}
 required: AnyRef{implicit val fooMsg: String}
       b = new { val fooMsgg: String = "v" }
           ^

I would either

  • parse implicit keyword and say "we will ignore it in typecheck as it can be overriden with non-implicit"
  • or just remove it form "toString" (the only problem is you can actually use this implicit), like annotations for example :
scala> val a = new { @volatile var fooMsg: String = "a" }
a: AnyRef{def fooMsg: String; def fooMsg_=(x$1: String): Unit} = $anon$1@2395330e //so it's steel annotaited, but typecheck doesn't see it
@scabug
Copy link
Author

scabug commented Jan 14, 2015

Imported From: https://issues.scala-lang.org/browse/SI-9085?orig=1
Reporter: Dmytro Kondratiuk (dk14)

@scabug
Copy link
Author

scabug commented Jan 16, 2015

@retronym said:
[~xeno.by] I wonder if any of your macro paradise based type provider use cases rely on implicits members in structural types. IIRC, you need macros in structural types, so this seems analagous.

If there are no use cases, I would favour removing the implicit flag from the symbol in inferred structural types.

@scabug
Copy link
Author

scabug commented Jan 17, 2015

@xeno-by said:
Jason, I don't think that I've ever used the IMPLICIT flag in structural types. Macros in refinement types let us combat runtime inefficiencies and provide additional means for language virtualization, but I can't imagine how i'd use implicits in refinement types. [~travisbrown], what's your take on this?

@SethTisue
Copy link
Member

Scala 3 (3.3.0-RC3) also rejects the explicit structural type:

scala> type Foo = AnyRef { given fooMsg: String }
-- Error: ----------------------------------------------------------------------
1 |type Foo = AnyRef { given fooMsg: String }
  |                    ^^^^^^^^^^^^^^^^^^^^
  |                    refinement cannot be `given`

and the loophole involving type inference is closed

scala> val a = new { given fooMsg: String = "a" }
val a: Object = anon$1@4bab78ce                                                                                              

closing the ticket, as I think a design change here is out of scope for Scala 2, especially since Scala 3 has kept the door shut on the structural type

@SethTisue SethTisue closed this as not planned Won't fix, can't repro, duplicate, stale Mar 16, 2023
@SethTisue SethTisue removed this from the Backlog milestone Mar 16, 2023
@scala scala deleted a comment from scabug Mar 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants