-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
image/draw: blank images after go1.18 #69721
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
It would be helpful to bisect to a single CL if you can do that. |
The behavior change was indeed caused by https://go.dev/cl/340049. CC @nigeltao |
Here's what's happening.
It also 'overrides' the Set method:
Overrides is in 'quotes' because Go isn't really object-oriented the way C++ or Java is. Note that Now, what happened in Go 1.18 is that there's new With Go 1.18 (and later), a @ianlancetaylor and others can correct me if I'm wrong, but I don't actually think this can be 'fixed' in the standard library, if we still want to keep the Instead, I think that Personally, I think that, in hindsight, Go's embedding feature is a mistake and methods should instead always be explicitly 'forwarded' to struct fields. Especially as doing so would avoid surprises like this. I would recommend (1), like this: @@ -66,7 +66,7 @@ func (cm Threshold) Inverse() Threshold {
// Each braille character represents 2x4 actual pixels.
type Gray struct {
// real holds the real pixel version of the image.
- *image.Gray
+ Gray *image.Gray
// content holds the braille representation of the image.
// Not using stdlib's single dim slice as benchmark shows
@@ -108,6 +108,9 @@ func NewGray(r image.Rectangle) *Gray {
return img
}
+func (p *Gray) At(x, y int) color.Color { return p.Gray.At(x, y) }
+func (p *Gray) Bounds() image.Rectangle { return p.Gray.Bounds() }
+
// Clear all pixels.
func (p *Gray) Clear() {
// The for loop is more efficient that a copy of empty element. This patch makes the |
Thanks for the analysis. I agree that this is not a bug in Go. The Go compatibility guarantee permits us to add methods to existing types. Any embedding of a type in the standard library must consider this possibility. |
Go version
go1.23.1 amd64/linux
Output of
go env
in your module/workspace:What did you do?
Pulled on old-ish (5years) project and tried to use it, but it is now broken. https://github.com/creack/bug
I bisected go major version and found that it started to break at go1.18, go1.17 was still working fine. Now the result is a blank image.
Simple project using stdlin only:
Checking using
go test
.What did you see happen?
All tests fail with blank images.
What did you expect to see?
Passing tests.
The text was updated successfully, but these errors were encountered: