[Bug go/100389] New: "invalid type conversion" error for string-based error type

ben.hutchings at essensium dot com gcc-bugzilla@gcc.gnu.org
Sun May 2 22:26:18 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100389

            Bug ID: 100389
           Summary: "invalid type conversion" error for string-based error
                    type
           Product: gcc
           Version: 10.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: ben.hutchings at essensium dot com
                CC: cmang at google dot com
  Target Milestone: ---

Given the following source files:

$ cat main.go
package main

import (
        "foo"
        "os"
)

func main() {
        if !foo.IsInUse(foo.Remove()) {
                os.Exit(1)
        }
}
$ cat src/foo/foo.go
package foo

const (
        errVolumeInUse conflictError = "volume is in use"
)

type conflictError string

func (e conflictError) Error() string {
        return string(e)
}

func IsInUse(err error) bool {
        return isErr(err, errVolumeInUse)
}

func isErr(err error, expected error) bool {
        return err == expected
}

func Remove() error {
        return errVolumeInUse
}

gccgo (from Debian package version 10.2.1-6) reports:

$ GOPATH=$PWD go build .
# _/home/bwh/tmp/gotest
 ./src/foo/foo.go:22: error: invalid type conversion (type has no methods)
 ./src/foo/foo.go:14: error: invalid type conversion (type has no methods)

Whereas gc (from Debian package version 1.15.9-1) builds these successfully.


More information about the Gcc-bugs mailing list