Skip to content

Topic/533 parse error #1847

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

Merged
merged 4 commits into from
Jan 8, 2017
Merged

Conversation

b-studios
Copy link
Contributor

@b-studios b-studios commented Dec 21, 2016

This pull request deals with "Parsers.scala:533". It is part of #1589.

Message Before

-- Error: examples/parser533.scala ---------------------------------------------
3 |} // error
  |^
  |`.' expected
-- [E025] Syntax Error: examples/parser533.scala -------------------------------
2 |  type X = FooBar22.this // error
  |           ^^^^^^^^^^^^^
  |           identifier expected

Explanation
===========
An identifier expected, but `FooBar22.this` found. This could be because
`FooBar22.this` is not a valid identifier. As a workaround, the compiler could
infer the type for you. For example, instead of:

def foo: FooBar22.this = {...}

Write your code like:

def foo = {...}



two errors found

Message After

-- [E036] Syntax Error: examples/parser533.scala -------------------------------
2 |  type X = FooBar22.this // error
  |           ^^^^^^^^^^^^^
  |           Expected an additional member selection after the keyword this

Explanation
===========
Paths of imports and type selections must not end with the keyword this.

Maybe you forgot to select a member of this? As an example, in the
following context:
  trait Outer {
    val member: Int
    type Member
    trait Inner {
      ...
    }
  }

- this is a valid import expression using a path
  import Outer.this.member
  //               ^^^^^^^

- this is a valid type using a path
  type T = Outer.this.Member
  //                 ^^^^^^^


one error found

In addition to adding the required error message this pull request also fixes some inconsistencies with referring to identifier literals. While in the doc-comments one could find Ident, ident, ident(), Id and id, in the spec identifiers are always referred to as id.

@b-studios
Copy link
Contributor Author

@felixmulder @Blaisorblade I am happy to fix the conflicts, once the PR has been reviewed.

@felixmulder
Copy link
Contributor

Paolo is probably a good reviewer for this PR in my opinion :) so I'll delegate to him ;)

@Blaisorblade
Copy link
Contributor

I'll try but I can't reply very timely these days...

@b-studios
Copy link
Contributor Author

Sorry @Blaisorblade, for a split-second while mentioning you, I forgot how busy you are these days. Maybe someone else can review this PR? Cheers and happy holidays!

@@ -901,4 +901,31 @@ object messages {
val msg = hl"trying to define package with same name as `$existing`"
val explanation = ""
}

case class DangelingThisInPath()(implicit ctx: Context) extends Message(34) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dangeling -> Dangling. (And given the delay, maybe recheck the ID 34).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val msg = hl"""Expected an additional member selection after the keyword ${"this"}"""

val importCode =
"""import MyClass.this.member
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use OuterClass instead of MyClass? And even add class OuterClass { class InnerClass { ... } } as context to show the point of MyClass.this? I ask because it took me a (small) while to get the point MyClass.this (I'll concede I might also be rusty).

@@ -504,7 +504,7 @@ object Parsers {
def selector(t: Tree): Tree =
atPos(startOffset(t), in.offset) { Select(t, ident()) }

/** Selectors ::= ident { `.' ident()
/** Selectors ::= id { `.' id }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good commit. Possible further idea: mention id in the comment for isIdent, also given they're not consistent? So authors of other comments can also find the right terminal name to use in comments?
(Well, being consistent might be even better but I'm not sure what to pick).
But that shouldn't hold this PR.

@Blaisorblade
Copy link
Contributor

LGTM apart from the comments (and even those are mostly optional) — sorry for the delay, I hadn't realized the review would be so quick!

@b-studios
Copy link
Contributor Author

b-studios commented Jan 7, 2017

@Blaisorblade Thanks for the review. I provided some more context to the code examples in 21194ba

@Blaisorblade
Copy link
Contributor

The CI failure is on http://dotty-ci.epfl.ch/lampepfl/dotty/475/1 at line 6164-6173.* That seems to have to do with a testcase from 18bc638 in #1850 — for some reason only 1 error is being output instead of 2.

Does this relate to switching error message from strings, or (in some complicated way) to adding , start as argument to syntaxError? I'm hoping the latter, but no clue why except if the if is skipped in
https://github.com/b-studios/dotty/blob/065377cadd9634b6fb48da561f1f504082fd06f5/compiler/src/dotty/tools/dotc/parsing/Parsers.scala#L111-L112.

BTW, with that change the caret is not on this (line 6167 in logs), and I'm not sure I like that.

*OT for @jvican, assuming you picked Drone: I can't find a way to link to specific log lines in Drone logs like I'd do in these cases with Travis. Am I missing something? Or any chance you could please forward this feature request to the right people?

@b-studios
Copy link
Contributor Author

b-studios commented Jan 8, 2017

I verified that, in deed, only one error is produced in presence of syntaxError(DanglingThisInPath(), start), while there are two with syntaxError(DanglingThisInPath()). Here are the two errors, of which one is missing:

-- [E036] Syntax Error: examples/parser533.scala -------------------------------
3 |}
  |^
  |Expected an additional member selection after the keyword this

longer explanation available when compiling with `-explain`
-- [E025] Syntax Error: examples/parser533.scala -------------------------------
2 |  type X = FooBar22.this // error
  |           ^^^^^^^^^^^^^
  |           identifier expected
longer explanation available when compiling with `-explain`

@felixmulder
Copy link
Contributor

felixmulder commented Jan 8, 2017

@Blaisorblade, @b-studios, haven't looked too closely at this, but FYI:

Error messages are pruned by UniqueMessagePositions.scala and HideNonSensicalMessages.scala. If positions are changed when modifying error messages, this is where they would be pruned out.

The caret is placed on the point of a position if it is focused, otherwise it will be a sort of underline of carets from pos.start to pos.end.

Regarding Drone, http://discourse.drone.io/ is probably the appropriate place to make a feature request. They also have a gitter: https://gitter.im/drone/drone

Cheers,
Felix

@b-studios
Copy link
Contributor Author

b-studios commented Jan 8, 2017

Thanks @felixmulder for the caret explanation. Changing the error call to syntaxError(DanglingThisInPath(), t.pos) will print as

2 |  type X = FooBar22.this // error
  |           ^^^^^^^^^^^^^
  |           Expected an additional member selection after the keyword this

@Blaisorblade Do you like that better?

However, the second error message "identifier expected" is still pruned away since it is located at the same message position.

@Blaisorblade
Copy link
Contributor

However, the second error message "identifier expected" is still pruned away since it is located at the same message position.

FWIW, looking at the two messages, I'd say pruning away "identifier expected" is an improvement :-), and the new position is much better.
In the future, I'd show the old error in the commit message to clarify the goal of the change.

TL;DR. I'd remove the second // error in the testcase (I'm guessing that comment marks expected errors), get a green build and merge.

Regarding Drone, http://discourse.drone.io/ is probably the appropriate place to make a feature request. They also have a gitter: https://gitter.im/drone/drone

Thanks, done here:
http://discourse.drone.io/t/feature-request-allow-links-to-specific-log-lines/150

@b-studios
Copy link
Contributor Author

@felixmulder Build now is successful. Is there something more I can do (like squashing, etc.), or are we ready to merge?

@felixmulder
Copy link
Contributor

I'd like the merge commit rebased away - otherwise LGTM 👍

@b-studios b-studios force-pushed the topic/533-parse-error branch 2 times, most recently from d74f40f to bc8af8f Compare January 8, 2017 18:34
The following examples trigger the error message:

    val x: Foo.this = ???

    // Also triggers the error:
    import foo.this

    // Additionally, also slays the compiler
    type X = Foo.this.type
To match the specs in
  https://github.com/lampepfl/dotty/blob/master/docs/syntax-summary.txt
all occurences of Id, ident or Ident in comments have been replaced
with the terminal `id`.
@b-studios b-studios force-pushed the topic/533-parse-error branch from bc8af8f to feba6a4 Compare January 8, 2017 18:37
@b-studios
Copy link
Contributor Author

@felixmulder I rebase the merge commit away and also squashed the typo-commit.

@felixmulder
Copy link
Contributor

Great, thanks a bunch! You're awesome 🎉

@felixmulder felixmulder merged commit 7113db7 into scala:master Jan 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants