Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Parameter *T Automatically Converted to *Base #2439

@xushiwei

Description

@xushiwei

Proposal

In Go, a recv *T pointer can be automatically converted to *Base. For example:

type Base struct {
    ...
}

func (p *Base) F() { ... }

type T struct {
    Base
}

A function call like p.F() is essentially equivalent to a call like (*Base).F(&p.Base), where &p.Base automatically converts the p *T into a *Base pointer.

We want the parameter behaviour in XGo to be consistent with the receiver pointer behaviour. That is, even if F is not a method but a function, this should still work:

func F(p *Base) { ... }

For a p *T, when we call F(p), no type error will be raised. Instead, it will be automatically converted to a function call like F(&p.Base).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions