Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3509)

Issue 99410046: code review 99410046: spec: explicitly disallow blank methods in interface types (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
9 years, 11 months ago by gri
Modified:
9 years, 11 months ago
Reviewers:
r, rsc, iant
CC:
r, rsc, ken2, iant, golang-codereviews
Visibility:
Public.

Description

spec: explicitly disallow blank methods in interface types The spec was unclear about whether blank methods should be permitted in interface types. gccgo permits at most one, gc crashes if there are more than one, go/types permits at most one. Discussion: Since method sets of non-interface types never contain methods with blank names (blank methods are never declared), it is impossible to satisfy an interface with a blank method. It is possible to declare variables of assignable interface types (but not necessarily identical types) containing blank methods, and assign those variables to each other, but the values of those variables can only be nil. There appear to be two "reasonable" alternatives: 1) Permit at most one blank method (since method names must be unique), and consider it part of the interface. This is what appears to happen now, with corner-case bugs. Such interfaces can never be implemented. 2) Permit arbitrary many blank methods but ignore them. This appears to be closer to the handling of blank identifiers in declarations. However, an interface type literal is not a declaration (it's a type literal). Also, for struct types, blank identifiers are not ignored; so the analogy with declarations is flawed. Both these alternatives don't seem to add any benefit and are likely (if only slightly) more complicated to explain and implement than disallowing blank methods in interfaces altogether. Fixes issue 6604.

Patch Set 1 #

Patch Set 2 : diff -r ddbcb0e26855 https://code.google.com/p/go/ #

Patch Set 3 : diff -r c75cb94e1357 https://code.google.com/p/go/ #

Patch Set 4 : diff -r 708e129e91a9 https://code.google.com/p/go/ #

Patch Set 5 : diff -r 708e129e91a9 https://code.google.com/p/go/ #

Patch Set 6 : diff -r 708e129e91a9 https://code.google.com/p/go/ #

Patch Set 7 : diff -r 1de165698f51 https://code.google.com/p/go/ #

Unified diffs Side-by-side diffs Delta from patch set Stats (+12 lines, -11 lines) Patch
M doc/go_spec.html View 1 2 3 4 chunks +12 lines, -11 lines 0 comments Download

Messages

Total messages: 6
gri
Hello r@golang.org, rsc@golang.org, ken@golang.org, iant@golang.org (cc: golang-codereviews@googlegroups.com), I'd like you to review this change to ...
9 years, 11 months ago (2014-05-22 17:09:57 UTC) #1
gri
Hello r@golang.org, rsc@golang.org, ken@golang.org, iant@golang.org (cc: golang-codereviews@googlegroups.com), Please take another look.
9 years, 11 months ago (2014-05-22 17:19:06 UTC) #2
r
LGTM i agree they should just be banned.
9 years, 11 months ago (2014-05-22 17:32:15 UTC) #3
rsc
LGTM
9 years, 11 months ago (2014-05-22 17:42:43 UTC) #4
iant
LGTM Would be nice to have a test in the testsuite for this, but not ...
9 years, 11 months ago (2014-05-22 19:03:22 UTC) #5
gri
9 years, 11 months ago (2014-05-22 19:23:29 UTC) #6
*** Submitted as https://code.google.com/p/go/source/detail?r=15feabceaef4 ***

spec: explicitly disallow blank methods in interface types

The spec was unclear about whether blank methods should be
permitted in interface types. gccgo permits at most one, gc
crashes if there are more than one, go/types permits at most
one.

Discussion:

Since method sets of non-interface types never contain methods
with blank names (blank methods are never declared), it is impossible
to satisfy an interface with a blank method.

It is possible to declare variables of assignable interface types
(but not necessarily identical types) containing blank methods, and
assign those variables to each other, but the values of those
variables can only be nil.

There appear to be two "reasonable" alternatives:

1) Permit at most one blank method (since method names must be unique),
and consider it part of the interface. This is what appears to happen
now, with corner-case bugs. Such interfaces can never be implemented.

2) Permit arbitrary many blank methods but ignore them. This appears
to be closer to the handling of blank identifiers in declarations.
However, an interface type literal is not a declaration (it's a type
literal). Also, for struct types, blank identifiers are not ignored;
so the analogy with declarations is flawed.

Both these alternatives don't seem to add any benefit and are likely
(if only slightly) more complicated to explain and implement than
disallowing blank methods in interfaces altogether.

Fixes issue 6604.

LGTM=r, rsc, iant
R=r, rsc, ken, iant
CC=golang-codereviews
https://codereview.appspot.com/99410046
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b