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

Test code error #5

Open
ggaaooppeenngg opened this issue Mar 31, 2014 · 2 comments
Open

Test code error #5

ggaaooppeenngg opened this issue Mar 31, 2014 · 2 comments

Comments

@ggaaooppeenngg
Copy link

In the Test_SessionsDeleteValue

    m.Get("/show", func(session Session) string {
        if session.Get("hello") == "world" {
            t.Error("Session value deleting failed")
        }
        return "OK"
    })

Get("hello") return interface of hello and it would never equals to string "world"。

@ggaaooppeenngg
Copy link
Author

sorry for this post
i tried the code
package main

import (
    "fmt"
)

func main() {
    var a interface{}
    a = "haha"
    fmt.Println(a=="haha")
}

it works ok,but how can a interface{} equals to a string?

@patricksuo
Copy link

http://golang.org/ref/spec#Comparison_operators

In any comparison, the first operand must be assignable to the type of the second operand, or vice versa.

A value x of non-interface type X and a value t of interface type T are comparable when values of
type X are comparable and X implements T. They are equal if t's dynamic type is identical to X and t's > dynamic value is equal to x.

http://golang.org/ref/spec#Types

Variables of interface type also have a distinct dynamic type, which is the actual type of the value
stored in the variable at run time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants