Wednesday, April 24, 2024
HomeGolangAssist with compile error, please - Getting Assist

Assist with compile error, please – Getting Assist


I’m pretty new to Golang. I’m making an attempt to implement what, within the C, language can be a tagged union. I discovered some instance code on: Go and Algebraic Information Varieties – Eli Bendersky’s web site

I believe I perceive the instance, and am making an attempt to emulate it in my code. Here’s a excerpt of my full program that will get an error that I don’t perceive. All of it appears okay to me.


package deal foremost

kind Obj interface {
    isObj()
}

kind Tspecial struct {
    subtype int
}

func (Tspecial) isObj() {}

func make_special(subtype int) *Obj {
	n := Tspecial{subtype}
	return &n
}

func foremost() {
    // dot := make_special(1)
}

It will get the next error with go model 1.19.1:

./take a look at.go:15:9: can’t use &n (worth of kind *Tspecial) as kind *Obj in return assertion:
*Tspecial doesn’t implement *Obj (kind *Obj is pointer to interface, not interface)

I believe I’ve issues such that Tspecial implement Obj, so why wouldn’t the handle of a Tspecial be a *Obj ?

In any case, can somebody please inform me my error. I’m positive there’s a technique to do what I’m making an attempt to do.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments