Git Product home page Git Product logo

Comments (6)

cosmos72 avatar cosmos72 commented on June 11, 2024

Thanks for spotting this!

The Go package reflect has some missing features - namely, it cannot create new recursive types, new interfaces or new named types at runtime.
Gomacro has a package github.com/cosmos72/gomacro/xreflect which emulates such missing features, but it's really complicated and error-prone.
The bugs you found are in such package - I will need some time to find a way to fix them without introducing regressions,
and (possibly) without further complicating it.

from gomacro.

cosmos72 avatar cosmos72 commented on June 11, 2024

Update: to be precise, there's a flag OptIncomplete that is set in a named type while constructing it.
The flag gets cleared once the named type is complete, but related types (such as pointers to the named type) created while the type is not yet complete, inherit the flag but don't clear it once the named type is completed.
It's a classic cache invalidation bug.

from gomacro.

cosmos72 avatar cosmos72 commented on June 11, 2024

Fixed in commit 1f88d82
Also, commit af24dc3 adds a test for this issue, to detect any future regression

from gomacro.

flamelx avatar flamelx commented on June 11, 2024

Great! Thank a million for the prompt fix.

from gomacro.

flamelx avatar flamelx commented on June 11, 2024
func case8() {
	type RR struct {
		A []*RR // diff
		B int
	}
	interp := fast.New()
	interp.DeclType(interp.Comp.TypeOf(RR{}))
	script := `func Execute()([]*RR,error){
			return nil,nil
		}`
	interp.Eval(script)
}

@cosmos72 The problem still occurs when a field is a slice. Could you help to see it again?

from gomacro.

flamelx avatar flamelx commented on June 11, 2024
func case8() {
	type RR struct {
		A []*RR // diff
		B int
	}
	interp := fast.New()
	interp.DeclType(interp.Comp.TypeOf(RR{}))
	script := `func Execute()([]*RR,error){
			return nil,nil
		}`
	interp.Eval(script)
}

@cosmos72 The problem still occurs when a field is a slice. Could you help to see it again? :p~

func case9() {
	type RR struct {
		A []*RR // diff
		B int
	}
	interp := fast.New()
	interp.DeclType(interp.Comp.TypeOf(RR{}))
	script := `func Execute()[]*RR{ 
			var rr []*RR
                         r:=&RR{} // r:=&RR{B:1} success
                         rr=append(rr,r)
			return rr
		}`
	interp.Eval(script)
	v, _ := interp.Eval("Execute()")
        // reflect.Value.Convert: value of type []xreflect.Forward cannot be converted to type []*RR
	v[0].Convert(reflect.TypeOf([]*RR{}))
        // success
	v[0].Index(0).Convert(reflect.TypeOf(&RR{}))
}

This is another issue.

from gomacro.

Related Issues (20)

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.