On Tuesday, September 4, 2018 at 11:49:23 AM UTC-5, rog wrote:
>
> selector goes away too. For example, the Stringer contract in the 
> design doc purports to check that there's a method named String, which 
> it does not - it could be a function-valued field instead. 
>
>
In your example, you could replace fmt.Sprint(x) with x.String() to
avoid the problem.

>From my reading, you can use the following to force a 'func (t T)
String() string' method, but you'll need a separate contract for 'func
(t *T) String() string'.

contract stringer(x T) {
        var _ string = T.String(x)
}

contract stringerp(x T) {
        var _ string = (*T).String(&x)
}

You can also force a 'String func() string' field:

contract stringerField(x T) {
        unsafe.Offsetof(x.String)
        var _ string = x.String()
}

Unrelated, but more unsafe abuse allows another type of odd contract
as well:

contract FourBytesOrLarger(x T) {
        var _ [unsafe.Sizeof(*(*T)(nil))-4]int
}


I don't think any of the above is a good idea, and the original
stringer contract probably does what you want it to 99% of the time.

- Todd 

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to