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

Member access expressions #989

Merged
merged 39 commits into from
Mar 2, 2022
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
df43587
Initial design changes for member access expressions
zygoloid Dec 15, 2021
b72d322
Filling out template with PR 989
zygoloid Dec 15, 2021
efe4d73
Rules for member access naming interface members.
zygoloid Dec 16, 2021
9a5da20
Merge branch 'trunk' into proposal-member-access-expres
zygoloid Jan 18, 2022
9e7e021
Text improvements
zygoloid Jan 19, 2022
4ea4f73
Add proposal text.
zygoloid Jan 19, 2022
46dde7f
Undo some damage done by `prettier`.
zygoloid Jan 19, 2022
138470d
Switch from blockquote to bullets to work around prettier bug.
zygoloid Jan 20, 2022
5413d9b
Add some cross-references to proposal background.
zygoloid Jan 21, 2022
93d9563
Address review comments.
zygoloid Jan 22, 2022
9ac1f4d
Apply suggestions from code review
zygoloid Jan 22, 2022
5cf7eb1
Address review comments.
zygoloid Jan 22, 2022
ea19037
Add missing `external`.
zygoloid Jan 22, 2022
0cb68a7
Add another couple of `external`s.
zygoloid Jan 22, 2022
f7f78d2
Address review comment.
zygoloid Jan 22, 2022
5ad6bc3
Summarize member access in a table and use more meaningful names in
zygoloid Jan 24, 2022
6120907
Flesh out "alternatives considered".
zygoloid Jan 24, 2022
aa8d643
Apply suggestions from code review
zygoloid Jan 25, 2022
0652f27
Missing update `a` -> `n` when switching example to nicer names.
zygoloid Jan 25, 2022
eeee8ee
Restructure: add better summary and overview at the start and explain
zygoloid Jan 26, 2022
70903f8
Attempt to clarify in response to review comments.
zygoloid Jan 26, 2022
735abac
Reflow to appease prettier.
zygoloid Jan 26, 2022
c6afd28
Apply suggestions from code review
zygoloid Jan 26, 2022
3ed3a43
Respond to review comments.
zygoloid Jan 26, 2022
a241782
Add elided word back for clarity.
zygoloid Jan 27, 2022
0d169e4
Attempt to clarify that lookup never considers the values of in-scope…
zygoloid Jan 27, 2022
05c41ef
Apply suggestions from code review
zygoloid Feb 1, 2022
babfee7
Clarify that we're not giving an example of a rewrite rule, just an
zygoloid Feb 1, 2022
4d9c39c
Response to review comments.
zygoloid Feb 1, 2022
b9427a4
Remove table of cases; it doesn't seem to pull its weight.
zygoloid Feb 1, 2022
27335b7
Factor out wording about combining lookup results and say that it takes
zygoloid Feb 1, 2022
2c09a73
Expand explanation in example.
zygoloid Feb 2, 2022
207347b
Add discussion of alternative interpretation of `Type.Interface`.
zygoloid Feb 2, 2022
e8a820c
Merge branch 'trunk' into proposal-member-access-expres
zygoloid Feb 2, 2022
751f02e
Fix trailing whitespace.
zygoloid Feb 2, 2022
a3bddec
Respond to review comments.
zygoloid Mar 2, 2022
dfab250
Merge branch 'trunk' into proposal-member-access-expres
zygoloid Mar 2, 2022
3f80189
Attempt to fix mermaid error: don't use underscore in node name.
zygoloid Mar 2, 2022
3ae955c
Fix '->' typo in mermaid diagram.
zygoloid Mar 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions docs/design/expressions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,21 @@ keyword and is not preceded by a period (`.`).
### Qualified names and member access

A _qualified name_ is a word that is prefixed by a period. Qualified names
appear as designators and in [member access](member_access.md) expressions of
the form
appear in the following contexts:

> _expression_ `.` _word_
- [Designators](/docs/design/classes.md#literals): `.` _word_
- [Direct member access expressions](member_access.md): _expression_ `.`
_word_

or
```
var x: auto = {.hello = 1, .world = 2};
^^^^^ ^^^^^ qualified name
^^^^^^ ^^^^^^ designator

> _expression_ `.` `(` _member-access-expression_ `)`
x.hello = x.world;
^^^^^ ^^^^^ qualified name
^^^^^^^ ^^^^^^^ member access expression
```

Qualified names refer to members of an entity determined by the context in which
the expression appears. For a member access, the entity is named by the
Expand All @@ -64,6 +71,7 @@ namespace N;
fn N.F() {}

fn G() {
// Same as `(Foo.N).F()`.
// `Foo.N` names namespace `N` in package `Foo`.
// `(Foo.N).F` names function `F` in namespace `N`.
Foo.N.F();
Expand All @@ -83,12 +91,15 @@ fn J() {
```

Member access expressions associate left-to-right. If the member name is more
complex than a single _word_, parentheses are required:
complex than a single _word_, an indirect member access expression can be used,
with parentheses around the member name:

- _expression_ `.` `(` _member-access-expression_ `)`

```
interface I { fn F[me: Self](); }
class X {}
impl X as I { fn F[me: Self]() {} }
external impl X as I { fn F[me: Self]() {} }

// `x.I.F()` would mean `(x.I).F()`.
fn Q(x: X) { x.(I.F)(); }
Expand Down
Loading