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

Field access of cast expression: discrepancy between parser-lalr and rustc #28362

Open
rprichard opened this Issue Sep 11, 2015 · 4 comments

Comments

Projects
None yet
5 participants
@rprichard
Copy link
Contributor

rprichard commented Sep 11, 2015

It's not clear to me whether this code is valid syntax. It looks wrong, so maybe it ought to be rejected. rustc rejects it, but parser-lalr accepts it:

struct S { f: i32 }
fn main() {
    let s = S { f: 42 };
    s as S.f;
}

It looks like it should parse as s as (S.f), and that wouldn't parse. parser-lalr parses it as (s as S).f

test.rs:4:11: 4:12 error: expected one of `!`, `(`, `::`, `;`, `<`, `}`, or an operator, found `.`
test.rs:4     s as S.f;
                    ^

(To test the LALR grammar, build the check-grammar target, then run grammar/parser-lalr -v.)

@brson

This comment has been minimized.

Copy link
Contributor

brson commented Mar 23, 2017

Current output:

rustc 1.16.0 (30cf806ef 2017-03-10)
error: expected one of `!`, `(`, `::`, `;`, `<`, or `}`, found `.`
 --> <anon>:4:11
  |
4 |     s as S.f;
  |           ^

error[E0308]: mismatched types
 --> <anon>:4:5
  |
4 |     s as S.f;
  |     ^^^^^^ expected (), found struct `S`
  |
  = note: expected type `()`
             found type `S`

error: aborting due to previous error

@brson brson added the T-lang label Mar 23, 2017

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 23, 2017

Seems clear that parser-lalr is wrong here.

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Mar 23, 2017

However, I can see why it arises. foo.bar is not a valid type, after all.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Oct 31, 2018

Triage; is parser-lalr still a thing? is this issue relevant?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.