Skip to content

Commit 260b424

Browse files
authored
Merge pull request scala#1709 from nogurenn/amend/outdated-symbol-sample-code
Other parts of this have the updated `___Name()` syntax. These examples were probably just missed. * Add explicit return type to outdated def line * Remove implicit TypeName/TermName conversion Based on deprecation doc of `stringToTermName` and `stringToTypeName`, people should avoid using these implicit conversions in particular. * Chang scope example from isOverride to isFinal `isOverride` is now private according to the 2.13 source. Changing the example to `isFinal` instead. * Polish doc
2 parents f032538 + 3eed41f commit 260b424

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

_overviews/reflection/annotations-names-scopes.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,7 @@ the `map` method (which is a term) declared in the `List` class, one can do:
8686
res1: scala.reflect.runtime.universe.Symbol = method map
8787

8888
To search for a type member, one can follow the same procedure, using
89-
`TypeName` instead. It is also possible to rely on implicit conversions to
90-
convert between strings and term or type names:
91-
92-
scala> listTpe.member("map": TermName)
93-
res2: scala.reflect.runtime.universe.Symbol = method map
89+
`TypeName` instead.
9490

9591
### Standard Names
9692

@@ -123,11 +119,11 @@ Additional functionality is exposed in *member scopes* that are returned by
123119
[scala.reflect.api.Scopes#MemberScope](https://www.scala-lang.org/api/current/scala-reflect/scala/reflect/api/Scopes$MemberScope.html)
124120
supports the `sorted` method, which sorts members *in declaration order*.
125121

126-
The following example returns a list of the symbols of all overridden members
122+
The following example returns a list of the symbols of all final members
127123
of the `List` class, in declaration order:
128124

129-
scala> val overridden = listTpe.decls.sorted.filter(_.isOverride)
130-
overridden: List[scala.reflect.runtime.universe.Symbol] = List(method companion, method ++, method +:, method toList, method take, method drop, method slice, method takeRight, method splitAt, method takeWhile, method dropWhile, method span, method reverse, method stringPrefix, method toStream, method foreach)
125+
scala> val overridden = listTpe.decls.sorted.filter(_.isFinal)
126+
overridden: List(method isEmpty, method map, method collect, method flatMap, method takeWhile, method span, method foreach, method reverse, method foldRight, method length, method lengthCompare, method forall, method exists, method contains, method find, method mapConserve, method toList)
131127

132128
## Exprs
133129

@@ -204,7 +200,8 @@ Constant expressions are used to represent
204200

205201
Example:
206202

207-
Literal(Constant(5))
203+
scala> Literal(Constant(5))
204+
val res6: reflect.runtime.universe.Literal = 5
208205

209206
The above expression creates an AST representing the integer literal `5` in
210207
Scala source code.
@@ -424,7 +421,7 @@ Positions can refer either to only a single character in a source file, or to
424421
a *range*. In the latter case, a *range position* is used (positions that are
425422
not range positions are also called *offset positions*). Range positions have
426423
in addition `start` and `end` offsets. The `start` and `end` offsets can be
427-
"focussed" on using the `focusStart` and `focusEnd` methods which return
424+
"focused" on using the `focusStart` and `focusEnd` methods which return
428425
positions (when called on a position which is not a range position, they just
429426
return `this`).
430427

_overviews/reflection/symbols-trees-types.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,14 +350,14 @@ For example, to look up the `map` method of `List`, one can do:
350350
scala> import scala.reflect.runtime.universe._
351351
import scala.reflect.runtime.universe._
352352

353-
scala> typeOf[List[_]].member("map": TermName)
353+
scala> typeOf[List[_]].member(TermName("map"))
354354
res0: scala.reflect.runtime.universe.Symbol = method map
355355

356356
Note that we pass method `member` a `TermName`, since we're looking up a
357357
method. If we were to look up a type member, such as `List`'s self type, `Self`, we
358358
would pass a `TypeName`:
359359

360-
scala> typeOf[List[_]].member("Self": TypeName)
360+
scala> typeOf[List[_]].member(TypeName("Self"))
361361
res1: scala.reflect.runtime.universe.Symbol = type Self
362362

363363
We can also query all members or declarations on a type in interesting ways.
@@ -707,7 +707,7 @@ there’s already a `parse` method built into the macro context. For example:
707707
scala> def impl(c: scala.reflect.macros.Context) = c.Expr[Unit](c.parse("println(2)"))
708708
impl: (c: scala.reflect.macros.Context)c.Expr[Unit]
709709

710-
scala> def test = macro impl
710+
scala> def test: Unit = macro impl
711711
test: Unit
712712

713713
scala> test

0 commit comments

Comments
 (0)