Skip to content

Should we remove the "suggestions" from parse error messages #315

Description

@apblack

A long time ago, I think as the result of a student project, many of the errors generated by the parser were accompanied by "suggestions" of possible fixes. I propose removing these suggestions.

For example:

identifierresolution.grace[1111:72]: Syntax error: a valid expression must follow '++'. This is often caused by a new line in the middle of an expression.
1110:         if (reusedScope.isLegalAsTrait.not) then {
1111:             errormessages.syntaxError ("the expression in your use " ++
-----------------------------------------------------------------------------^

Did you mean:
  1111:             errormessages.syntaxError ("the expression in your use "

Did you mean:
  1111:             errormessages.syntaxError ("the expression in your use " ++ «expression»

Did you mean:
  1111: 

That example is moderately helpful, in that the suggestions are at least syntactically correct. (The actual problem was my failure to indent the continuation line). Others are less helpful

identifierresolution.grace[160:18]: Syntax error: an elseif statement must have a condition in braces after the 'elseif'.
 159:             ast.identifierNode.new("$" ++ v, false) scope(self)
 160:         } elseif (outerChain.isEmpty) then {
-----------------------^

Did you mean:
  160:         } elseif { (outerChain.isEmpty }) then {

and

identifierresolution.grace[162:29]: Syntax error: an if statement must have 'then' after the condition in parentheses.
 161:         def v = s.variety
 162:         if (v == "dialect") || (v == "builtIn")) then {
----------------------------------^

Did you mean:
  162:         if (v == "dialect") then { || (v == "builtIn")) then {

where the suggestion is syntactic garbage.

In response to issue #243, I have already moved the spelling correction suggestions for undeclared identifiers into the error message, so these would not be affected by this proposal.

Why remove them?

  • The suggestion code is a mess; it is not factored out of the main parser logic (except in a few cases where I have moved it), so it makes the parser module much longer and less maintainable.

  • The suggestions are often wrong

  • Students almost always use the IDE, in which case they never see them

  • Highlighting the location where the parser detected the error (as with ^^^ in the above examples is much more useful; more experienced programmers (i.e., me :-) ) never look at the suggestions.

The only one that is useful is

scope.grace[239:21-22]: Syntax error: a definition must use '=' instead of ':='. A variable declaration uses 'var' and ':='.
 238:     var statusOfReusedNames := "undiscovered"
 239:     def methodTypes := dictionary.empty
--------------------------^^

Did you mean:
  239:     def methodTypes = dictionary.empty

Did you mean:
  239:     var methodTypes := dictionary.empty

but even here, the error message already says what is necessary.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions