Skip to content

Proof that golang's interface type (nil) current judgement is wrong #67879

Closed as not planned
@ruyi789

Description

@ruyi789

Proposal Details

Example:

var a *st //struct
if a==nil //true,yes

var b = any(a) //

a0,yes := b.(*st)
if yes==true //true,yes
if a0==nil//true,yes

if b==nil//(false, yes or no?) The problem arises here when someone argues that this judgement should not hold, based on the type assertion (a0,yes := b.(*st)).

But I think this is wrong, the if b==nil judgement should be based on a value judgement (true,yes), not on a type judgement (false,no). If you make a type judgement

(a0,yes := b.(*st)) is sufficient, the only thing missing is the value judgement of the interface type (essentially the compiler is judging two interfaces of the same type by the value judgement, which is a bit confusing).

Interface type occupies two pointers {typeinfo_ptr, value_ptr}, we should take the judgement (value_ptr) judgement (nil), such as integers (0==0, 1!=0), pointers can also be understood as a kind of value. The following connection example causes problems exactly what I said!

https://go.dev/play/p/pnVn1mT6Keg

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