File: t6651.scala

package info (click to toggle)
scala 2.11.12-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 62,924 kB
  • sloc: javascript: 28,808; java: 13,415; xml: 3,135; sh: 1,620; python: 756; makefile: 38; awk: 36; ansic: 6
file content (33 lines) | stat: -rw-r--r-- 1,070 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
class YouAreYourself[A <: AnyRef](val you: A) extends AnyVal {
  def yourself: you.type = you
}

object Test {
  val s = ""
  val s1: s.type = new YouAreYourself[s.type](s).yourself
}

trait Path {
  type Dep <: AnyRef
}

final class ValueClass[P <: Path](val path: P) extends AnyVal {
  import path.Dep

  def apply(dep: Dep)(d2: dep.type, foo: Int): (Dep, d2.type) = (d2, d2)

  // This generates dodgy code; note `ValueClass.this`:
  //
  // final def bounds$extension[D >: Nothing <: ValueClass.this.path.Dep,
  //                            P >: Nothing <: Path]
  //                            ($this: ValueClass[P])
  //                            (dep: D)
  //                            (d2: dep.type, foo: Int): (D, d2.type) = scala.Tuple2.apply[D, d2.type](d2, d2);
  //
  // Nothing crashes down the line, but it certainly doesn't conform to best-practices.
  //
  // An better alternative would be to add a type parameter for the (singleton) type of
  // the wrapped value.
  def bounds[D <: Dep](dep: D)(d2: dep.type, foo: Int): (D, d2.type) = (d2, d2)
}