Skip to content

spec: define when return is necessary #65

@gopherbot

Description

@gopherbot

by bob.appleyard:

func example(x int) int {
    if x == 0 {
        return 5;
    } else {
        return x;
    }
}

Gives the error "function ends without a return statement"

Changing it to:

func example(x int) int {
    if x == 0 {
        return 5;
    } else {
        return x;
    }
    panic("unreachable");
}

Solves the problem, however this is quite clearly a workaround.


GOOS=linux
GOARCH=amd64

Local revision:

changeset:   3988:b773b8255a8f
tag:         tip
user:        Russ Cox <rsc@golang.org>
date:        Wed Nov 11 13:08:35 2009 -0800
summary:     avoid clash with stdio's getc, ungetc.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions