Skip to content

Complex types can't be used as method receivers #1716

@edsrzf

Description

@edsrzf
Test program:

package main

type cplx complex64

func (c cplx) Foo() {}

func main() {
    var c cplx
    c.Foo()
}

Compiler output:
test.go:5: invalid receiver type cplx
test.go:9: c.Foo undefined (type cplx has no field or method Foo)

The same thing happens with complex128.

I notice in gc/align.c, there's a commented out line that would make
issimple[TCOMPLEX64] and issimple[TCOMPLEX128] true. I'm pretty sure uncommenting that
line would fix this problem, but presumably it was commented out for a reason, so I'll
leave this to someone who knows more about it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions