Should lazy val bitmap be synthetic?

71 views
Skip to first unread message

Christopher Currie

unread,
Feb 17, 2014, 6:13:10 PM2/17/14
to scala-i...@googlegroups.com
Sorry for the newbie question. I'm looking at the lazy val implementation, and for the moment I'm restricted to Java reflection to introspect the class.

I'm running across the "bitmap$0" field, which IIUC is used to synchronize access to the lazy val to ensure it's initialized.

Because it's possible (though pedantic and probably not recommended) to create an Int field with the name `bitmap$0`, I was hoping to find it tagged as synthetic, so that I could be sure it's a compiler generated artifact, and not a user field. But it appears this is not the case.


Should this field be synthetic? Are there any disadvantages to make it so?

Thanks in advance,
Christopher Currie

Simon Ochsenreither

unread,
Feb 18, 2014, 8:20:57 AM2/18/14
to scala-i...@googlegroups.com
Imho, yes.

martin odersky

unread,
Feb 18, 2014, 10:02:50 AM2/18/14
to scala-internals



On Tue, Feb 18, 2014 at 2:20 PM, Simon Ochsenreither <simon.och...@gmail.com> wrote:
Imho, yes.

I agree. Note though that Scala reserves the '$'-sign. There are no guarantees that user-defined identifiers containing '$'-signs will not clash with compiler-generated identifiers today or in the future.

Cheers

 - Martin

--
You received this message because you are subscribed to the Google Groups "scala-internals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-interna...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.



--
Martin Odersky
EPFL

Haoyi Li

unread,
Feb 18, 2014, 11:29:13 AM2/18/14
to scala-i...@googlegroups.com
I've always wondered about this, so sorry for jumping in here: why doesn't scalac just encode $s in user-defined identifiers, just like it encodes any other weird characters it finds? Seems to me like the added complexity will be outweighed by the removal of another "you can do this, BUT DONT" type of rule.

Adriaan Moors

unread,
Feb 19, 2014, 2:01:11 AM2/19/14
to scala-i...@googlegroups.com
Good question! We use the $ in the library when we want to avoid clashing with user code, so you'd need an escape hatch.
Backticks could serve that purpose (or privileging the scala package).
Perhaps we could require 66 ticks on front and back to avoid accidentally backticked dollars.

I'll add it to our lint collection.
Reply all
Reply to author
Forward
0 new messages