Git Product home page Git Product logo

diff's People

Contributors

bmizerany avatar kr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

bmizerany

diff's Issues

stack overflow when transforming from T to slice/struct with a T

These tests fail due to stack overflows:

func TestSOs(t *testing.T) {     
        t.Run("T to []T", func(t *testing.T) {
                diff.Test(t, t.Errorf, "a", "b", diff.Transform(func(s string) any { 
                        return []string{s}     
                }))              
        })                  
        t.Run("T to struct{V T}", func(t *testing.T) {
                diff.Test(t, t.Errorf, "a", "b", diff.Transform(func(s string) any { 
                        return struct{ S string }{s}
                }))                            
        })                                    
} 

panic diffing map with struct value type

Go Version

go version go1.18.2 darwin/arm64

Current kr.dev/diff commit 6c69dcc

I'm using diff.Test with a map[string]someStruct and seeing this panic:

diff % go test
--- FAIL: TestBug (0.00s)
panic: reflect.Value.UnsafeAddr of unaddressable value [recovered]
	panic: reflect.Value.UnsafeAddr of unaddressable value

goroutine 321 [running]:
testing.tRunner.func1.2({0x10119ed80, 0x1011ea1d0})
	/usr/local/go/src/testing/testing.go:1389 +0x1c8
testing.tRunner.func1()
	/usr/local/go/src/testing/testing.go:1392 +0x384
panic({0x10119ed80, 0x1011ea1d0})
	/usr/local/go/src/runtime/panic.go:838 +0x204
reflect.Value.UnsafeAddr(...)
	/usr/local/go/src/reflect/value.go:2528
kr.dev/diff.access({0x10119e380?, 0x1400029fbc0?, 0x1400029fbc0?})
	/Users/bmizerany/src/diff/diff.go:494 +0x90
kr.dev/diff.(*differ).walk(0x1400029d580, {0x1011ecd20, 0x140002e24e0}, {0x1011b7f60?, 0x1400029fbc0?, 0x1400029fbc8?}, {0x1011b7f60?, 0x1400029fbc8?, 0x14000050b68?}, 0x1, ...)
	/Users/bmizerany/src/diff/diff.go:330 +0x239c
kr.dev/diff.(*differ).walk(0x1400029d580, {0x1011ecd20, 0x140002e2340}, {0x1011adc40?, 0x14000010bd8?, 0x1011ba660?}, {0x1011adc40?, 0x14000010be0?, 0x14000043e78?}, 0x1, ...)
	/Users/bmizerany/src/diff/diff.go:360 +0x2110
kr.dev/diff.(*differ).each(0x1400029d580, {0x1011adc40, 0x140002e40c0}, {0x1011adc40?, 0x140002e40f0})
	/Users/bmizerany/src/diff/diff.go:242 +0x27c
kr.dev/diff.Test({0x1011eb408, 0x140002dc680}, 0x101131ee0?, {0x1011adc40, 0x140002e40c0}, {0x1011adc40, 0x140002e40f0}, {0x0, 0x0, 0x0})
	/Users/bmizerany/src/diff/diff.go:75 +0x138
kr.dev/diff_test.TestBug(0x140002dc680)
	/Users/bmizerany/src/diff/diff_test.go:388 +0xe4
testing.tRunner(0x140002dc680, 0x1011e94d0)
	/usr/local/go/src/testing/testing.go:1439 +0x110
created by testing.(*T).Run
	/usr/local/go/src/testing/testing.go:1486 +0x300
exit status 2
FAIL	kr.dev/diff	0.160s

A minimal test to reproduce:

func TestBug(t *testing.T) {
	type T struct {
		F int
	}

	got := map[string]T{
		"k": {},
	}

	want := map[string]T{
		"k": {},
	}

	diff.Test(t, t.Errorf, got, want)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.