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

logictest: avoid a lint failure #92593

Merged
merged 1 commit into from
Nov 28, 2022
Merged

Conversation

knz
Copy link
Contributor

@knz knz commented Nov 28, 2022

Fixes #92592

The go compiler treats calls to bazel.BuiltWithBazel() as a
compile-time constant. Therefore,

if !bazel.BuiltWithBazel() {
   skip.XXX()
}

is considered to always terminate execution (because skip does its
job by raising a panic), and any code coming after that is treated as
dead/unreachable.

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm: but please say more in the commit message. Say that builtWithBazel is a compile-time constant; it took me a second to make sense of what's going on here.

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @knz and @rickystewart)


-- commits line 4 at r2:
@rafiss , any chance we can make this cockroach-go stuff work with make too? I don't see any discussion about it in #91881; it seems like a dubious precedent to me. It causes this kind of nonsense.


pkg/sql/logictest/logic.go line 1809 at r1 (raw file):

	// Prevent a lint failure "this function is unused" when
	// bazel.BuiltWithBazel returns false below.
	_ = t.newTestServerCluster

I think this should go next to the newTestServerCluster definition, and say that the function is only used in bazel builds.


pkg/sql/logictest/logic.go line 1831 at r2 (raw file):

		}

		// Prevent a lint failure "this function is unused" when

The right message is this value is never used. Consider writing that, as it provides more of a hint to what the linter is complaining about.


pkg/sql/logictest/logic.go line 1833 at r2 (raw file):

		// Prevent a lint failure "this function is unused" when
		// bazel.BuiltWithBazel returns false above.
		_ = bootstrapBinaryPath

So the linter detects that the read below is unreachable, but does not detect that the write is also unreachable? Grr

Copy link
Contributor Author

@knz knz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please say more in the commit message

Done

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained (waiting on @andreimatei and @rickystewart)


pkg/sql/logictest/logic.go line 1809 at r1 (raw file):

Previously, andreimatei (Andrei Matei) wrote…

I think this should go next to the newTestServerCluster definition, and say that the function is only used in bazel builds.

We can't - it's a method. We can only "access" it after there's an object it's bound to.

(It would be different if we had unit tests for this feature, but we don't)


pkg/sql/logictest/logic.go line 1831 at r2 (raw file):

Previously, andreimatei (Andrei Matei) wrote…

The right message is this value is never used. Consider writing that, as it provides more of a hint to what the linter is complaining about.

Done.


pkg/sql/logictest/logic.go line 1833 at r2 (raw file):

Previously, andreimatei (Andrei Matei) wrote…

So the linter detects that the read below is unreachable, but does not detect that the write is also unreachable? Grr

😭

@knz
Copy link
Contributor Author

knz commented Nov 28, 2022

bors r=andreimatei

Copy link
Contributor

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (and 1 stale) (waiting on @knz and @rickystewart)


pkg/sql/logictest/logic.go line 1809 at r1 (raw file):

Previously, knz (Raphael 'kena' Poss) wrote…

We can't - it's a method. We can only "access" it after there's an object it's bound to.

(It would be different if we had unit tests for this feature, but we don't)

sure you can:

var _ = (&logicTest{}).newTestServerCluster

@knz
Copy link
Contributor Author

knz commented Nov 28, 2022

bors r-

@craig
Copy link
Contributor

craig bot commented Nov 28, 2022

Canceled.

@knz
Copy link
Contributor Author

knz commented Nov 28, 2022

bors r=andreimatei

The go compiler treats calls to `bazel.BuiltWithBazel()` as a
compile-time constant. Therefore,

```go
if !bazel.BuiltWithBazel() {
   skip.XXX()
}
```

is considered to always terminate execution (because `skip` does its
job by raising a panic), and any code coming after that is treated as
dead/unreachable.

Release note: None
@craig
Copy link
Contributor

craig bot commented Nov 28, 2022

Canceled.

@knz
Copy link
Contributor Author

knz commented Nov 28, 2022

bors r=andreimatei

@craig
Copy link
Contributor

craig bot commented Nov 28, 2022

Build succeeded:

@craig craig bot merged commit 1bc257b into cockroachdb:master Nov 28, 2022
@knz knz deleted the 20221128-fix-github branch November 29, 2022 14:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bazel CI not finding test failures related
3 participants