Skip to content

Switch interface assertion is invalid #1

@1514599514

Description

@1514599514

The following program sample.go triggers an unexpected result

package main

import (
	"github.com/GoCodeAlone/yaegi/interp"
	"github.com/GoCodeAlone/yaegi/stdlib"
)

const src = `
package main

import (
	"fmt"
)

type User struct {
	Name string
	Age  int
}
	
func printAnyType(arg any) {
	switch arg.(type) {
	case User:
		fmt.Println("User")
	default:
		fmt.Println("unknown")
	}
}

func main() {
	fmt.Println("start eval")
	u := User{Name: "name", Age: 18}
	printAnyType(u)
}
`

func main() {
	i := interp.New(interp.Options{})

	i.Use(stdlib.Symbols)

	_, err := i.Eval(src)
	if err != nil {
		panic(err)
	}
}

Expected result

start eval
User

Got

start eval
unknown

Yaegi Version

v0.17.1

Additional Notes

Only the switch assertion is invalid
The assertion of a regular interface is normal

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions