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

cmd/compile: include name in "unexpected name" error message #11814

Closed
carcinocron opened this issue Jul 22, 2015 · 4 comments
Closed

cmd/compile: include name in "unexpected name" error message #11814

carcinocron opened this issue Jul 22, 2015 · 4 comments
Milestone

Comments

@carcinocron
Copy link

Context: http://tour.golang.org/flowcontrol/8

func Sqrt(x float64) float64 {
    z := float64(1)

    z = z - (z^2 - x)/2z

    return z
}

I get the same results for:

   z = z - math.Pow(z,2) - x/2z;

results:

/tmp/sandbox898777084/main.go:10: syntax error: unexpected name, expecting semicolon or newline or }

Looks like I can't progress on the problem because I'm stuck on syntax.

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Jul 22, 2015
@ianlancetaylor
Copy link
Contributor

CC @adg @campoy

@adg
Copy link
Contributor

adg commented Jul 22, 2015

The syntax error is 2z. You need an operator between the 2 and the z. I think what you want is 2*z.

We could probably improve the compiler error. Maybe it could say what the unexpected name was ("z"?).

@adg adg changed the title tour: flowcontrol 8 sqrt math fails giving unrelatable message: syntax error: unexpected name, expecting semicolon or newline or } cmd/compiler: include name in "unexpected name" error message Jul 22, 2015
@adg adg modified the milestones: Go1.6, Unreleased Jul 22, 2015
@josharian josharian changed the title cmd/compiler: include name in "unexpected name" error message cmd/compile: include name in "unexpected name" error message Aug 21, 2015
@gopherbot
Copy link

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

@rsc
Copy link
Contributor

rsc commented Dec 5, 2015

With Robert's new parser the error is:

/tmp/x.go:6: syntax error: unexpected z at end of statement

Clear enough I think.

@rsc rsc closed this as completed Dec 5, 2015
@golang golang locked and limited conversation to collaborators Dec 14, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants