You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_spec/04-basic-declarations-and-definitions.md
+51-29Lines changed: 51 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -248,7 +248,7 @@ type ´t´ >: Nothing
248
248
type ´t´ >: [´\mathit{tps'}\,´] =>> ´L´
249
249
<: [´\mathit{tps'}\,´] =>> ´U´
250
250
```
251
-
251
+
252
252
If at least one of the ´\mathit{tps}´ contains an explicit variance annotation, then ´\mathit{tps'} = \mathit{tps}´, otherwise we infer the variance of each type parameter as with the user-written type lambda `[´\mathit{tps}\,´] =>> ´U´`.
253
253
254
254
The same desugaring applies to typeparameters. For instance,
@@ -695,64 +695,86 @@ completely. It is an error if the types of two alternatives ´T_i´ and
695
695
696
696
##ImportClauses
697
697
698
-
```ebnf
699
-
Import::= ‘import’ ImportExpr {‘,’ ImportExpr}
700
-
ImportExpr::=StableId ‘.’ (id | ‘_’ |ImportSelectors)
-In a `NamedSelector`, `=>` can only be used when inside an `ImportSelectors` and is then equivalent to `as`, to be deprecated in the future.
712
+
-In a `WildcardSelector`, `_` is equivalent to `*`, to be deprecated in the future.
713
+
714
+
An `ImportSpecifier` that is a single `NamedSelector` or `WildcardSelector` is equivalent to an `‘{‘ ImportSelectors ‘}‘` list with that single selector.
715
+
716
+
Animportclausewithmultipleimportexpressions`import ´p_1´.´I_1, ..., p_n´.´I_n´`isinterpreted as asequenceofimportclauses`import ´p_1´.´I_1´; ...; import ´p_n´.´I_n´`.
705
717
706
-
Animportclausehastheform`import ´p´.´I´`where ´p´ isa [stableidentifier](03-types.html#paths) and ´I´ isanimportexpression.
Animportclausewithasingleimportexpressionhastheform`import ´p´.´I´`where ´p´ isa [prefix](03-types.html#designator-types) and ´I´ isanimportspecifier.
719
+
Theimportspecifierdeterminesasetofnamesofimportablemembersof ´p´ whicharemadeavailablewithoutqualification as well as asetofimportable`given`memberswhicharemadeavailableintheimplicitscope.
708
720
A member ´m´ of ´p´ is _importable_ if it is [accessible](05-classes-and-objects.html#modifiers).
709
-
The most general form of an importexpressionisalistof_importselectors_
721
+
The most general form of an importspecifierisalistof_importselectors_
710
722
711
723
```scala
712
-
{ ´x_1´ => ´y_1, ..., x_n´ => ´y_n´, _ }
724
+
{ ´x_1´ as ´y_1, ..., x_n´ as ´y_n´, *, given ´T_1´, ..., given ´T_m´, given }
713
725
```
714
726
715
-
for ´n \geq 0´, where the final wildcard `‘_’` may be absent.
716
-
It makes available each importable member `´p´.´x_i´` under the unqualified name ´y_i´. I.e. every importselector`´x_i´ => ´y_i´`renames`´p´.´x_i´`to
717
-
´y_i´.
718
-
If a final wildcard is present, all importable members ´z´ of ´p´ other than `´x_1, ..., x_n,y_1, ..., y_n´` are also made available under their own unqualified names.
727
+
for ´n \geq 0´ and ´m \geq 0´, where the wildcards `‘*’` and `’given’` may be absent.
728
+
They are decomposed into non-givenselectors and givenselectors.
719
729
720
-
Import selectors work in the same way fortypeand term members.
721
-
For instance, an importclause`import ´p´.{´x´ => ´y\,´}`renamestheterm
722
-
name `´p´.´x´` to the term name ´y´ and the typename `´p´.´x´` to the typename ´y´.
730
+
###Non-givenImports
731
+
732
+
Non-givenselectors make available each importable member `´p´.´x_i´` under the unqualified name ´y_i´.
733
+
In other words, every importselector`´x_i´ as ´y_i´`renames`´p´.´x_i´`to ´y_i´.
734
+
When `as ´y_i´` is omitted, ´y_i´ is assumed to be ´x_i´.
735
+
If a final wildcard `‘*’` is present, all non-`given` importable members ´z´ of ´p´ other than `´x_1, ..., x_n, y_1, ..., y_n´` are also made available under their own unqualified names.
736
+
737
+
Non-givenimport selectors work in the same way fortypeand term members.
738
+
For instance, an importclause`import ´p´.{´x´ => ´y´}`renamesthetermname`´p´.´x´`tothetermname ´y´ andthetypename`´p´.´x´`tothetypename ´y´.
723
739
At least one of these two names must reference an importable member of ´p´.
724
740
725
-
If the target in an importselectorisawildcard, theimportselectorhidesaccesstothesourcemember.
726
-
For instance, the importselector`´x´ => _` “renames” ´x´ tothewildcardsymbol (whichisunaccessible as anameinuserprograms), andtherebyeffectivelypreventsunqualifiedaccessto ´x´.
741
+
If the target in an importselectorisanunderscore`as _`, theimportselectorhidesaccesstothesourcememberinsteadofimportingit.
742
+
For instance, the importselector`´x´ as _` “renames” ´x´ totheunderscoresymbol (whichisnotaccessible as anameinuserprograms), andtherebyeffectivelypreventsunqualifiedaccessto ´x´.
727
743
This is useful if there is a final wildcard in the same importselectorlist, whichimportsallmembersnotmentionedinpreviousimportselectors.
728
744
729
-
The scope of a binding introduced by an import-clause starts immediately after the importclauseandextendstotheendoftheenclosingblock, template, packageclause, orcompilationunit, whichevercomesfirst.
745
+
The scope of a binding introduced by a non-givenimportclause starts immediately after the importclauseandextendstotheendoftheenclosingblock, template, packageclause, orcompilationunit, whichevercomesfirst.
730
746
731
-
Several shorthands exist. Animportselectormaybejustasimplename ´x´.
732
-
Inthiscase, ´x´ is imported without renaming, so the importselectorisequivalentto`´x´ => ´x´`.
733
-
Furthermore, it is possible to replace the whole importselectorlistbyasingleidentifierorwildcard.
734
-
Theimportclause`import ´p´.´x´`isequivalentto`import ´p´.{´x\,´}`, i.e. itmakesavailablewithoutqualificationthemember ´x´ of ´p´. Theimportclause`import ´p´._`isequivalentto`import ´p´.{_}`, i.e. itmakesavailablewithoutqualificationallmembersof ´p´ (thisisanalogousto`import ´p´.*`inJava).
747
+
###GivenImports
735
748
736
-
Animportclausewithmultipleimportexpressions`import ´p_1´.´I_1, ..., p_n´.´I_n´`isinterpreted as asequenceofimportclauses`import ´p_1´.´I_1´; ...; import ´p_n´.´I_n´`.
749
+
Given selectors make available in the implicit scope all the importable `given` and `implicit` members `´p´.´x´` such that `´p.x´` is a subtype of ´T_i´.
750
+
A bare `given` selector without typeis equivalent to `given scala.Any`.
751
+
752
+
The names of the givenmembers are irrelevant for the selection, and are not made available in the normal scope of unqualified names.
0 commit comments