From 103c9db74737afc67c394e3c68c746ba176f2b49 Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 1 Mar 2012 13:57:49 -0800 Subject: [PATCH] spec: clarifications around exports, uniqueness of identifiers - Define what it means for two identifiers to be unique. - The current spec is incorrect about exported identifiers: for instance, it excluded fields of non-exported types of exported variables from being exported. It is easier to leave the detailed specification away and let the rest of the spec govern access of exported identifiers. - The current spec is incorrect about qualified identifiers: It simply required that an identifier be exported to be valid in a qualified identifier. However, qualified identifiers can only access exported identifiers declared in the package block of the imported package. Fixes #1551. R=r, rsc, iant, ken CC=golang-dev https://golang.org/cl/5711043 --- doc/go_spec.html | 72 +++++++++++++++++++++++++++++------------------- 1 file changed, 44 insertions(+), 28 deletions(-) diff --git a/doc/go_spec.html b/doc/go_spec.html index 4880d69921..adc8a62c9a 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -684,7 +684,8 @@ The method set of the corresponding pointer type *T is the set of all methods with receiver *T or T (that is, it also contains the method set of T). Any other type has an empty method set. -In a method set, each method must have a unique method name. +In a method set, each method must have a +unique method name.

@@ -895,7 +896,7 @@ A struct is a sequence of named elements, called fields, each of which has a name and a type. Field names may be specified explicitly (IdentifierList) or implicitly (AnonymousField). Within a struct, non-blank field names must -be unique. +be unique.

@@ -1074,7 +1075,8 @@ InterfaceTypeName  = TypeName .
 

-As with all method sets, in an interface type, each method must have a unique name. +As with all method sets, in an interface type, each method must have a +unique name.

@@ -1538,10 +1540,19 @@ the body of any nested function.
 

+

Blank identifier

+ +

+The blank identifier, represented by the underscore character _, may be used in a declaration like +any other identifier but the declaration does not introduce a new binding. +

+ +

Predeclared identifiers

-The following identifiers are implicitly declared in the universe block: +The following identifiers are implicitly declared in the +universe block:

 Types:
@@ -1564,28 +1575,31 @@ Functions:
 

Exported identifiers

-An identifier may be exported to permit access to it from another package -using a qualified identifier. An identifier -is exported if both: +An identifier may be exported to permit access to it from another package. +An identifier is exported if both:

    -
  1. the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and
  2. -
  3. the identifier is declared in the package block or denotes a field or method of a type - declared in that block.
  4. +
  5. the first character of the identifier's name is a Unicode upper case + letter (Unicode class "Lu"); and
  6. +
  7. the identifier is declared in the package block + or it is a field name or + method name.

All other identifiers are not exported.

-

Blank identifier

+

Uniqueness of identifiers

-The blank identifier, represented by the underscore character _, may be used in a declaration like -any other identifier but the declaration does not introduce a new binding. +Given a set of identifiers, an identifier is called unique if it is +different from every other in the set. +Two identifiers are different if they are spelled differently, or if they +appear in different packages and are not +exported. Otherwise, they are the same.

-

Constant declarations

@@ -1942,7 +1956,7 @@ is visible only within selectors for that type.

For a base type, the non-blank names of -methods bound to it must be unique. +methods bound to it must be unique. If the base type is a struct type, the non-blank method and field names must be distinct.

@@ -2022,12 +2036,12 @@ QualifiedIdent = [ PackageName "." ] identifier .

A qualified identifier accesses an identifier in a different package, which must be imported. -The identifier must be exported by that -package, which means that it must begin with a Unicode upper case letter. +The identifier must be exported and +declared in the package block of that package.

-math.Sin
+math.Sin	// denotes the Sin function in package math
 

Composite literals

@@ -2332,8 +2346,8 @@ where T is not an interface type, x.f denotes the field or method at the shallowest depth in T where there is such an f. -If there is not exactly one f with shallowest depth, the selector -expression is illegal. +If there is not exactly one f +with shallowest depth, the selector expression is illegal.
  • For a variable x of type I @@ -5070,11 +5084,12 @@ An implementation may require that all source files for a package inhabit the sa

    Import declarations

    -An import declaration states that the source file containing the -declaration uses identifiers -exported by the imported -package and enables access to them. The import names an -identifier (PackageName) to be used for access and an ImportPath +An import declaration states that the source file containing the declaration +depends on functionality of the imported package +(§Program initialization and execution) +and it enables access to exported identifiers +of that package. +The import names an identifier (PackageName) to be used for access and an ImportPath that specifies the package to be imported.

    @@ -5086,13 +5101,14 @@ ImportPath = string_lit .

    The PackageName is used in qualified identifiers -to access the exported identifiers of the package within the importing source file. +to access exported identifiers of the package within the importing source file. It is declared in the file block. If the PackageName is omitted, it defaults to the identifier specified in the package clause of the imported package. If an explicit period (.) appears instead of a name, all the -package's exported identifiers will be declared in the current file's -file block and can be accessed without a qualifier. +package's exported identifiers declared in that package's +package block will be declared in the importing source +file's file block and can be accessed without a qualifier.

    -- 2.50.0