Idents and Selections

116 views
Skip to first unread message

Matan Safriel

unread,
Sep 10, 2015, 2:48:09 AM9/10/15
to scala-internals
Hi,

I have glimpsed at https://groups.google.com/forum/#!searchin/scala-internals/ident/scala-internals/Ms9WUAtokLo/sXD9eI94jX8J, and my question is what are the semantics of an Ident and how are they different from that of a Select?

I wonder whether Ident has very distinct semantics, somehow beyond the particular ways that the compiler manipulates it.

This may help perfecting my compiler plugin, which visualizes relationships between code entities, and derives higher-level meanings from trees.

Thanks,
Matan

Jason Zaugg

unread,
Sep 10, 2015, 3:19:20 AM9/10/15
to scala-i...@googlegroups.com

An Ident represents a reference to a named entity. We give it meaning by typechecking it, according the the rules of binding. It may bind to A) a name defined in an enclosing scope, or B) a member of an enclosing self type, or C) to an entity brought into a scope via an import.

In case B and C, the typechecker will sometimes expand the Ident into a Select.

Here’s an example of this in action

Typechecking will also assign a Symbol to the resulting Ident or Select to link it do the entity it references (the definition already has the same Symbol assigned), and compute its type. The type is computed based on the prefix of the selection, so Some(Int).get gets the type Int, rather than A

Hope this helps,

-jason

Matan Safriel

unread,
Sep 10, 2015, 1:30:22 PM9/10/15
to scala-internals
Thanks a lot, I just didn't get the example about Some(Int).get. What is A?
May I also assume from your answer that Selects are used only for this purpose of holding type-resolved references to entities?

Naftoli Gugenheim

unread,
Sep 10, 2015, 8:04:44 PM9/10/15
to scala-internals

Select means the dot "operator."
I guess A is get's declared return type, which in the call site context can be resolved to Int.


--
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/d/optout.

Miles Sabin

unread,
Sep 12, 2015, 6:34:32 AM9/12/15
to scala-internals
In that example, why the "this" in the expansion of "identity" when
there isn't one in the expansion of "Predef"?

Cheers,


Miles

--
Miles Sabin
tel: +44 7813 944 528
skype: milessabin
gtalk: mi...@milessabin.com
http://milessabin.com/blog
http://twitter.com/milessabin

Jason Zaugg

unread,
Sep 16, 2015, 10:19:53 AM9/16/15
to scala-i...@googlegroups.com
On Sat, Sep 12, 2015 at 8:34 PM Miles Sabin <mi...@milessabin.com> wrote:
In that example, why the "this" in the expansion of "identity" when
there isn't one in the expansion of "Predef"?

Good question! I dug into it, and it turns out that the root import of scala.Predef._ is actually being generated as scala.this.Predef._ (where scala.this is a ThisType referring to the scala package class.)

I’ve tracked this and proposed a fix over at SI-9473

-jason
Reply all
Reply to author
Forward
0 new messages