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

compiler/checker: 'declared and not used' error not reported in type switch statements #474

Closed
zapateo opened this issue Nov 25, 2019 · 0 comments
Labels
non-gc-compliant Non compliant with Go command tchecker Related to type checker

Comments

@zapateo
Copy link
Member

zapateo commented Nov 25, 2019

package main

func main() {
	switch v := interface{}(4).(type) {
	}
}

should report the error v declared and not used but Scriggo executes without any problem.

Note that this behaviour meets the Golang specs but it's not coherent with gc.

From https://golang.org/ref/spec#Variable_declarations:

Implementation restriction: A compiler may make it illegal to declare a variable inside a function body if the variable is never used.

This bug was intentionally introduced when #230 has been closed.

@zapateo zapateo changed the title compiler/checker: 'declared and not used' error not reported by type switch compiler/checker: 'declared and not used' error not reported in type switch statements Nov 25, 2019
@zapateo zapateo added this to the Milestone 1 milestone Dec 2, 2019
@zapateo zapateo added the bug Bug: something already implemented does not work as it should label Jan 8, 2020
@gazerro gazerro removed this from the Milestone 1 milestone Jun 9, 2021
@gazerro gazerro added non-gc-compliant Non compliant with Go command tchecker Related to type checker and removed bug Bug: something already implemented does not work as it should labels Jul 10, 2021
gazerro added a commit that referenced this issue Jul 19, 2021
This commit fixes some unreported errors in the type switch. For the
following example, the type checker does not report the error
'x declared but not used'

  switch x := interface{}(0).(type) { case int: }

For the following example, the type checker does not report the error
'x redeclared in this block'

  switch x := interface{}(0).(type) { case int: var x = 5; _ = x }

This commit fixes these issues and reports the errors in the same
position reported by gc.

Fixes #474
gazerro added a commit that referenced this issue Jul 20, 2021
This commit fixes some unreported errors in the type switch. For the
following example, the type checker does not report the error
'x declared but not used'

  switch x := interface{}(0).(type) { case int: }

For the following example, the type checker does not report the error
'x redeclared in this block'

  switch x := interface{}(0).(type) { case int: var x = 5; _ = x }

This commit fixes these issues and reports the errors in the same
position reported by gc.

Fixes #474
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
non-gc-compliant Non compliant with Go command tchecker Related to type checker
Projects
None yet
Development

No branches or pull requests

2 participants