Skip to content

cmd/compile: improve error message when if statement brace is on next line #18747

Closed

Description

@zigo101

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.7.4 linux/amd64

What did you do?

package main

func main() {
	a := 1
	
	for a = 1; a < 2; a++ // syntax error: missing { after for clause
	{
	}
	
	if a == 1 // missing condition in if statement
	{
	}
}

What did you expect to see?

the two error messages should be alike.

What did you see instead?

the the second error message is not very accurate.

Activity

  1. mvdan commented on Jan 22, 2017

    @mvdan
    Member

    Happens all the same on go version devel +4cce27a3fa Sat Jan 21 03:20:55 2017 +0000 linux/amd64 .

    @golang101 perhaps retitle to something like cmd/compile: wrong error when the opening brace of an if is on a new line

  2. changed the title [-]error message needs improving[/-] [+]cmd/compile: improve error message when if statement brace is on next line[/+] on Jan 22, 2017
  3. josharian commented on Jan 22, 2017

    @josharian
    Contributor

    @golang101 thanks for filing issues. Would you mind helping the folks doing triage by identifying the relevant component in the issue title, when you know it? Thanks!

    cc @odeke-em

  4. mvdan commented on Jan 22, 2017

    @mvdan
    Member

    @josharian did you mean that triage sentence towards me? I haven't requested github access, maybe I should.

  5. josharian commented on Jan 22, 2017

    @josharian
    Contributor

    It was meant for @golang101. But you should definitely request GitHub access.

  6. added this to the Go1.9 milestone on Jan 22, 2017
  7. added
    NeedsFixThe path to resolution is known, but the work has not been done.
    on Jan 22, 2017
  8. zigo101 commented on Jan 23, 2017

    @zigo101
    ContributorAuthor

    @josharian I would like to.

  9. gopherbot commented on Feb 4, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/36317 mentions this issue.

  10. mdempsky commented on Feb 4, 2017

    @mdempsky
    Contributor

    Syntactically,

    if foo
    {
    }
    

    is the same as

    if foo; {}
    

    And the latter produces a "missing condition in if statement" error, which is why the former does too.

    It's not obvious that the former deserves a different error message; or that if it does, what exactly should be the criteria for producing something different. I'd like to establish that before we worry about CLs.

  11. bradfitz commented on Feb 4, 2017

    @bradfitz
    Contributor

    @mdempsky, I bet only about 2% of Go users know that semicolons are even in the language at all, much less know the insertion rules.

    I personally think it deserves a better error message. A fair number of newcomers to the language are going to write code in that style before they discover gofmt.

  12. odeke-em commented on Feb 4, 2017

    @odeke-em
    Member

    @mdempsky, yeah, I agree with @bradfitz's explanation,
    I too think it deserves a better error message.

    As we can see in the issue report, the user who reported it found the same problem.

    if condition
    {
    }

    wasn't intuitive since visually they already provided the condition a == 1

    Getting the same message for

    if expression; {
    }

    that tells me to think about the missing condition in the style

    if expression; condition {

    even though expression might be a condition.

  13. gopherbot commented on Feb 13, 2017

    @gopherbot
    Contributor

    CL https://golang.org/cl/36930 mentions this issue.

  14. griesemer commented on Feb 15, 2017

    @griesemer
    Contributor
  15. locked and limited conversation to collaborators on Feb 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions