Skip to content

Commit 630d4fb

Browse files
griesemergopherbot
authored andcommitted
spec: document that alias declarations can have type parameters with 1.24
For #46477. Change-Id: Id02d8f67fe82228bab3f26b1cb4ebd6ee67c4634 Reviewed-on: https://go-review.googlesource.com/c/go/+/616816 Reviewed-by: Ian Lance Taylor <[email protected]> Auto-Submit: Robert Griesemer <[email protected]> Reviewed-by: Rob Pike <[email protected]> Reviewed-by: Robert Griesemer <[email protected]> TryBot-Bypass: Robert Griesemer <[email protected]>
1 parent aa42d7b commit 630d4fb

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

doc/go_spec.html

+29-2
Original file line numberDiff line numberDiff line change
@@ -2511,12 +2511,12 @@ <h4 id="Alias_declarations">Alias declarations</h4>
25112511
</p>
25122512

25132513
<pre class="ebnf">
2514-
AliasDecl = identifier "=" Type .
2514+
AliasDecl = identifier [ TypeParameters ] "=" Type .
25152515
</pre>
25162516

25172517
<p>
25182518
Within the <a href="#Declarations_and_scope">scope</a> of
2519-
the identifier, it serves as an <i>alias</i> for the type.
2519+
the identifier, it serves as an <i>alias</i> for the given type.
25202520
</p>
25212521

25222522
<pre>
@@ -2526,6 +2526,24 @@ <h4 id="Alias_declarations">Alias declarations</h4>
25262526
)
25272527
</pre>
25282528

2529+
<p>
2530+
If the alias declaration specifies <a href="#Type_parameter_declarations">type parameters</a>
2531+
[<a href="#Go_1.24">Go 1.24</a>], the type name denotes a <i>generic alias</i>.
2532+
Generic aliases must be <a href="#Instantiations">instantiated</a> when they
2533+
are used.
2534+
</p>
2535+
2536+
<pre>
2537+
type set[P comparable] = map[P]bool
2538+
</pre>
2539+
2540+
<p>
2541+
In an alias declaration the given type cannot be a type parameter.
2542+
</p>
2543+
2544+
<pre>
2545+
type A[P any] = P // illegal: P is a type parameter
2546+
</pre>
25292547

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

@@ -8687,6 +8705,15 @@ <h4 id="Go_1.23">Go 1.23</h4>
86878705
function as range expression.
86888706
</li>
86898707
</ul>
8708+
8709+
<h4 id="Go_1.24">Go 1.24</h4>
8710+
<ul>
8711+
<li>
8712+
An <a href="#Alias_declarations">alias declaration</a> may declare
8713+
<a href="#Type_parameter_declarations">type parameters</a>.
8714+
</li>
8715+
</ul>
8716+
86908717
<h3 id="Type_unification_rules">Type unification rules</h3>
86918718

86928719
<p>

0 commit comments

Comments
 (0)