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

Interface conversion panic when import a package #1426

Closed
JalinWang opened this issue Jul 5, 2022 · 1 comment
Closed

Interface conversion panic when import a package #1426

JalinWang opened this issue Jul 5, 2022 · 1 comment
Labels
area/core bug Something isn't working

Comments

@JalinWang
Copy link

JalinWang commented Jul 5, 2022

The following program sample.go triggers an unexpected result

package main

import (
	"github.com/casbin/casbin/v2"
)

func main() {
	e, err := casbin.NewEnforcer("./examples/rbac_with_pattern_model.conf", "./examples/rbac_with_pattern_policy.csv")
	if err != nil {
		panic(err)
	}
	// e := &Enforcer{logger: &log.DefaultLogger{}}
	println(e)
}

Expected result

$ go run main.go
0xc000024080

Got

$ yaegi.exe run github.com\casbin\main
E:\Programming\GO_PATH\src\github.com\casbin\main\vendor\github.com\casbin\casbin\v2\enforcer.go:75:26: panic
E:\Programming\GO_PATH\src\github.com\casbin\main\main.go:33:12: panic
panic: interface conversion: interface {} is nil, not map[string]map[string]*struct { Key string; Value string; Tokens []string; Policy [][]string; PolicyMap map[string]int; RM interface {}; FieldIndexMap map[string]int; Xlogger interface {} } [recovered]
        panic: interface conversion: interface {} is nil, not map[string]map[string]*struct { Key string; Value string; Tokens []string; Policy [][]string; PolicyMap map[string]int; RM interface {}; FieldIndexMap map[string]int; Xlogger interface {} } [recovered]
        panic: interface conversion: interface {} is nil, not map[string]map[string]*struct { Key string; Value string; Tokens []string; Policy [][]string; PolicyMap map[string]int; RM interface {}; FieldIndexMap map[string]int; Xlogger interface {} }

goroutine 1 [running]:
github.com/traefik/yaegi/interp.runCfg.func1()
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:192 +0x145
panic({0x135ee00, 0xc001eb1080})
        D:/Programming/Go/src/runtime/panic.go:838 +0x207
github.com/traefik/yaegi/interp.runCfg.func1()
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:192 +0x145
panic({0x135ee00, 0xc001eb1080})
        D:/Programming/Go/src/runtime/panic.go:838 +0x207
github.com/traefik/yaegi/interp.typeAssert.func3(0xc001ea09a0)
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:438 +0x639
github.com/traefik/yaegi/interp.runCfg(0xc0000b4a20, 0xc001ea09a0, 0xc001eb3560?, 0x1354640?)
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:200 +0x29d
github.com/traefik/yaegi/interp.call.func9(0xc001ea08f0)
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:1433 +0x94a
github.com/traefik/yaegi/interp.runCfg(0xc001eb3680, 0xc001ea08f0, 0xc001eb2b40?, 0xc0012eb7f8?)
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:200 +0x29d
github.com/traefik/yaegi/interp.(*Interpreter).run(0xc00037a000, 0xc001eb2b40, 0xc00037c000?)
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/run.go:119 +0x374
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0xc00037a000, {0x147d580, 0x4}, {0xc00002a2b8, 0x16}, 0x1)
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/src.go:168 +0xb52
github.com/traefik/yaegi/interp.(*Interpreter).EvalPath(0xc00037a000, {0xc00002a2b8, 0x16})
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/interp/interp.go:504 +0xdb
main.run({0xc00007e060?, 0x1, 0x2})
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/cmd/yaegi/run.go:118 +0xc0b
main.main()
        E:/Programming/GO_PATH/pkg/mod/github.com/traefik/yaegi@v0.13.0/cmd/yaegi/yaegi.go:133 +0xd4

Yaegi Version

0.13

Additional Notes

It shows the error counter at this line in the package:
image

However, after I copy the related code into my main.go, it works.

image

package main

import (
	"github.com/casbin/casbin/v2/effector"
	"github.com/casbin/casbin/v2/log"
	"github.com/casbin/casbin/v2/model"
	"github.com/casbin/casbin/v2/persist"
	"github.com/casbin/casbin/v2/rbac"
)

type Enforcer struct {
	modelPath string
	model     model.Model
	fm        model.FunctionMap
	eft       effector.Effector

	adapter    persist.Adapter
	watcher    persist.Watcher
	dispatcher persist.Dispatcher
	rmMap      map[string]rbac.RoleManager

	enabled              bool
	autoSave             bool
	autoBuildRoleLinks   bool
	autoNotifyWatcher    bool
	autoNotifyDispatcher bool

	logger log.Logger
}

func main() {
	// e, err := casbin.NewEnforcer("./examples/rbac_with_pattern_model.conf", "./examples/rbac_with_pattern_policy.csv")
	// if err != nil {
	// 	panic(err)
	// }
	e := &Enforcer{logger: &log.DefaultLogger{}}
	println(e)
}
@mvertes mvertes added bug Something isn't working area/core labels Aug 23, 2022
mvertes added a commit to mvertes/yaegi that referenced this issue Aug 29, 2022
The representation of non empty interfaces defined in the interpreter
is now identical between refType() and frameType() functions, which are
used to generate interpreter objects.

Fixes traefik#1447 and traefik#1426.
mvertes added a commit to mvertes/yaegi that referenced this issue Aug 29, 2022
The representation of non empty interfaces defined in the interpreter
is now identical between refType() and frameType() functions, which are
used to generate interpreter objects.

Fixes traefik#1447 and traefik#1426.
traefiker pushed a commit that referenced this issue Sep 1, 2022
The representation of non empty interfaces defined in the interpreter is now identical between refType() and frameType() functions, which are used to generate interpreter objects.

Fixes #1447 and #1426.
@mvertes
Copy link
Member

mvertes commented Sep 2, 2022

Fixed by #1448

@mvertes mvertes closed this as completed Sep 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/core bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants