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

go/types: accepts weird invalid program #20770

Closed
josharian opened this issue Jun 23, 2017 · 7 comments
Closed

go/types: accepts weird invalid program #20770

josharian opened this issue Jun 23, 2017 · 7 comments

Comments

@josharian
Copy link
Contributor

@josharian josharian commented Jun 23, 2017

package p

var r = newReader()

func newReader() r
$ gotype x.go
$ go tool compile x.go 
x.go:3:9: typechecking loop involving newReader
	x.go:3:18 newReader()
	x.go:3:5 r = newReader()
	x.go:3:5 r
	x.go:5:15 <T>
	x.go:5:18 newReader
	x.go:5:6 <node DCLFUNC>
x.go:5:18: r is not a type

The cmd/compile error message is pretty ugly, but I'll file a separate issue for that.

Marking as unplanned, because of the oddity and unlikeliness of the program.

Found with go-fuzz.

@josharian
Copy link
Contributor Author

@josharian josharian commented Jun 23, 2017

@ianlancetaylor I'd be curious to know what gccgo does with this snowflake.

Loading

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 23, 2017

gccgo output:

foo.go:5:18: error: expected type
 func newReader() r
                  ^
foo.go:3:9: error: reference to undefined name ‘newReader’
 var r = newReader()
         ^

Loading

@josharian
Copy link
Contributor Author

@josharian josharian commented Jun 23, 2017

gccgo definitely wins the compiler shootout on this one. :)

Loading

@griesemer griesemer self-assigned this Jun 23, 2017
@griesemer griesemer added this to the Go1.10 milestone Jun 23, 2017
@griesemer griesemer removed this from the Unplanned milestone Jun 23, 2017
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 23, 2017

go/types cycle detection has several issues. It's time to rethink/overhaul the mechanism.

Loading

@rsc rsc removed this from the Go1.10 milestone Nov 22, 2017
@rsc rsc added this to the Go1.11 milestone Nov 22, 2017
@griesemer
Copy link
Contributor

@griesemer griesemer commented Dec 16, 2017

diff --git a/src/go/types/decl.go b/src/go/types/decl.go
index b1ae5ef3f2..b1e98d91fb 100644
--- a/src/go/types/decl.go
+++ b/src/go/types/decl.go
@@ -96,6 +96,7 @@ func (check *Checker) objDecl(obj Object, def *Named, path []*TypeName) {
                check.typeDecl(obj, d.typ, def, path, d.alias)
        case *Func:
                // functions may be recursive - no need to track dependencies
+               check.decl = d
                check.funcDecl(obj, d)
        default:
                unreachable()

leads to usable error message. Need to investigate further to see if that is the right approach.

(cycle detection in go/types could use a fundamental overhaul).

Loading

@griesemer
Copy link
Contributor

@griesemer griesemer commented May 31, 2018

Possibly related to Duplicate of #8699.

Loading

@griesemer griesemer closed this May 31, 2018
@gopherbot
Copy link

@gopherbot gopherbot commented Jun 6, 2018

Change https://golang.org/cl/116815 mentions this issue: go/types: extend cycle detection past simple type cycles

Loading

gopherbot pushed a commit that referenced this issue Jun 7, 2018
This change improves upon cycle detection by taking into account
cycles involving constants, variables, _and_ types. All new code
(except for the additional tests) is guarded by the useCycleMarking
(internal) flag and thus can be disabled on short notice if it
introduced new problems. (The intent is to remove this flag shortly
after 1.11 is released.)

The test suite has been extended with various additional (and mostly
esoteric) test cases which now correctly report cycles. A handful of
existing test cases now report additional errors, but those are mostly
esoteric cases. Overall, this is an improvement over the status quo.

Fixes #8699.
For #20770.

Change-Id: I6086719acd0d5200edca4a3dbe703d053496af31
Reviewed-on: https://go-review.googlesource.com/116815
Run-TryBot: Robert Griesemer <gri@golang.org>
Reviewed-by: Alan Donovan <adonovan@google.com>
@golang golang locked and limited conversation to collaborators Jun 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants