Skip to content

Resolving issue in extended types #2110

Closed
@dmytro-vovk

Description

@dmytro-vovk

In this code:

package main

import (
    "encoding/json"
    "errors"
    "fmt"
)

type MyType struct {
    Err   string
    Error error `json:"-"`
}

func (m MyType) MarshalJSON() ([]byte, error) {
    type t MyType
    out := t(m)
    if out.Error != nil { // out.Error marked as unresolved reference
        out.Err = out.Error.Error() // here both out.Err and out.Error are unresolved references
    }
    return json.Marshal(out)
}

func main() {
    e := MyType{
        Err: "hello",
    }
    e.Error = errors.New("bad error")
    out, _ := json.Marshal(e)
    fmt.Printf("Output: %s", string(out))
}

IDEA: 15.x
Plugin: 0.10.859 and many previous versions

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions