Skip to content

Commit

Permalink
interp: fix type assertion issues
Browse files Browse the repository at this point in the history
closes #1514

hi!
I had the same problem as #1514 and I wanted to fix it, I found
When asserting *crypto/rsa.PublicKey, using the typ attribute of node to get an nil rtype, resulting in the assertion result being nok

This code contains the same problem
```go
package main

import (
	"log"
	"crypto/rsa"
)

func main() {

    var pKey interface{} = &rsa.PublicKey{}

    if _, ok := pKey.(*rsa.PublicKey); ok {
        log.Println("ok")
    } else {
        log.Println("nok")
    }
}

```

So I submitted this Pull Request, hope it will be merged
  • Loading branch information
ssbeatty authored Mar 14, 2023
1 parent 166fff7 commit 9d65860
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions _test/assert3.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package main

import "crypto/rsa"

func main() {
var pKey interface{} = &rsa.PublicKey{}

if _, ok := pKey.(*rsa.PublicKey); ok {
println("ok")
} else {
println("nok")
}
}

// Output:
// ok
2 changes: 1 addition & 1 deletion interp/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func typeAssert(n *node, withResult, withOk bool) {

typ := c1.typ // type to assert or convert to
typID := typ.id()
rtype := typ.rtype // type to assert
rtype := typ.refType(nil) // type to assert
next := getExec(n.tnext)

switch {
Expand Down

0 comments on commit 9d65860

Please sign in to comment.