Comments (6)
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.
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.
Fixed in commit 1f88d82
Also, commit af24dc3 adds a test for this issue, to detect any future regression
from gomacro.
Great! Thank a million for the prompt fix.
from gomacro.
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.
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)
- I would like a full working example how to inject my application context(types and functions) in the REPL HOT 9
- Extract struct with methods from script to compiled code HOT 2
- Proxy can mix the called method of the imported structure HOT 3
- integrate with https://github.com/go-rod/rod HOT 2
- I'm unable to compile code importing gomacro on Mac OS m1 pro HOT 7
- Is there a way to Eval a folder HOT 5
- can't import fsm package HOT 4
- Different compilation behaviour from native go HOT 2
- undefined: pkgpath HOT 3
- Cannot convert struct to interface if it has an embedded struct with a method HOT 4
- Cannot import third party packages on Linux (not even the ones in the README) HOT 2
- Third-party imported type method is not callable from fast.Interp.Eval [gomacro repl works] HOT 4
- Idea for making adding third party packages to Gomacro easier when plugins aren't available HOT 3
- recursive type error cases: call of reflect.Value.Interface on zero Value
- can not import 3rd party packages HOT 13
- package <package> exports zero constants, functions, types, and variables HOT 3
- Caching of interp.Eval1 results HOT 13
- Way to disable go get import and enforce to use only defined import list HOT 3
- An error will be reported when using third-party packages on Windows HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gomacro.