Skip to content

Commit

Permalink
spec: document that alias declarations can have type parameters with …
Browse files Browse the repository at this point in the history
…1.24

For #46477.

Change-Id: Id02d8f67fe82228bab3f26b1cb4ebd6ee67c4634
Reviewed-on: https://go-review.googlesource.com/c/go/+/616816
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Robert Griesemer <gri@google.com>
Reviewed-by: Rob Pike <r@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
TryBot-Bypass: Robert Griesemer <gri@google.com>
  • Loading branch information
griesemer authored and gopherbot committed Oct 2, 2024
1 parent aa42d7b commit 630d4fb
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions doc/go_spec.html
Original file line number Diff line number Diff line change
Expand Up @@ -2511,12 +2511,12 @@ <h4 id="Alias_declarations">Alias declarations</h4>
</p>

<pre class="ebnf">
AliasDecl = identifier "=" Type .
AliasDecl = identifier [ TypeParameters ] "=" Type .
</pre>

<p>
Within the <a href="#Declarations_and_scope">scope</a> of
the identifier, it serves as an <i>alias</i> for the type.
the identifier, it serves as an <i>alias</i> for the given type.
</p>

<pre>
Expand All @@ -2526,6 +2526,24 @@ <h4 id="Alias_declarations">Alias declarations</h4>
)
</pre>

<p>
If the alias declaration specifies <a href="#Type_parameter_declarations">type parameters</a>
[<a href="#Go_1.24">Go 1.24</a>], the type name denotes a <i>generic alias</i>.
Generic aliases must be <a href="#Instantiations">instantiated</a> when they
are used.
</p>

<pre>
type set[P comparable] = map[P]bool
</pre>

<p>
In an alias declaration the given type cannot be a type parameter.
</p>

<pre>
type A[P any] = P // illegal: P is a type parameter
</pre>

<h4 id="Type_definitions">Type definitions</h4>

Expand Down Expand Up @@ -8687,6 +8705,15 @@ <h4 id="Go_1.23">Go 1.23</h4>
function as range expression.
</li>
</ul>

<h4 id="Go_1.24">Go 1.24</h4>
<ul>
<li>
An <a href="#Alias_declarations">alias declaration</a> may declare
<a href="#Type_parameter_declarations">type parameters</a>.
</li>
</ul>

<h3 id="Type_unification_rules">Type unification rules</h3>

<p>
Expand Down

0 comments on commit 630d4fb

Please sign in to comment.