Skip to content

Commit 2febab1

Browse files
committed
Make instance a reserved word
# Conflicts: # compiler/src/dotty/tools/dotc/transform/Splicer.scala
1 parent 712fa3a commit 2febab1

File tree

9 files changed

+36
-35
lines changed

9 files changed

+36
-35
lines changed

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ object Tokens extends TokensCommon {
179179
final val FORSOME = 61; enter(FORSOME, "forSome") // TODO: deprecate
180180
final val ENUM = 62; enter(ENUM, "enum")
181181
final val ERASED = 63; enter(ERASED, "erased")
182-
final val WITNESS = 64; enter(WITNESS, "witness")
182+
final val INSTANCE = 64; enter(INSTANCE, "instance")
183+
final val WITNESS = 65; enter(WITNESS, "witness")
183184

184185
/** special symbols */
185186
final val NEWLINE = 78; enter(NEWLINE, "end of statement", "new line")

compiler/src/dotty/tools/dotc/quoted/QuoteDriver.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ class QuoteDriver extends Driver {
3636

3737
val clazz = classLoader.loadClass(driver.outputClassName.toString)
3838
val method = clazz.getMethod("apply")
39-
val instance = clazz.getConstructor().newInstance()
39+
val inst = clazz.getConstructor().newInstance()
4040

41-
method.invoke(instance).asInstanceOf[T]
41+
method.invoke(inst).asInstanceOf[T]
4242
}
4343

4444
def show(expr: Expr[_], settings: Toolbox.Settings): String = {

compiler/src/dotty/tools/dotc/transform/Splicer.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ object Splicer {
113113
}
114114

115115
protected def interpretStaticMethodCall(moduleClass: Symbol, fn: Symbol, args: => List[Object])(implicit env: Env): Object = {
116-
val (instance, clazz) =
116+
val (inst, clazz) =
117117
if (moduleClass.name.startsWith(str.REPL_SESSION_LINE)) {
118118
(null, loadReplLineClass(moduleClass))
119119
} else {
120-
val instance = loadModule(moduleClass)
121-
(instance, instance.getClass)
120+
val inst = loadModule(moduleClass)
121+
(inst, inst.getClass)
122122
}
123123

124124
def getDirectName(tp: Type, name: TermName): TermName = tp.widenDealias match {
@@ -129,7 +129,7 @@ object Splicer {
129129

130130
val name = getDirectName(fn.info.finalResultType, fn.name.asTermName)
131131
val method = getMethod(clazz, name, paramsSig(fn))
132-
stopIfRuntimeException(method.invoke(instance, args: _*))
132+
stopIfRuntimeException(method.invoke(inst, args: _*))
133133
}
134134

135135
protected def interpretModuleAccess(fn: Symbol)(implicit env: Env): Object =

tests/pos/opaque-groups-params.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package object groups {
44
}
55

66
object Semigroup {
7-
def instance[A](f: (A, A) => A): Semigroup[A] =
7+
def inst[A](f: (A, A) => A): Semigroup[A] =
88
new Semigroup[A] {
99
def combine(x: A, y: A): A = f(x, y)
1010
}
@@ -37,14 +37,14 @@ package object groups {
3737
def wraps[G[_], A](ga: G[A]): G[First[A]] = ga // error: overriding
3838
def unwrap[G[_], A](gfa: G[First[A]]): G[A] = gfa
3939
implicit def firstSemigroup[A]: Semigroup[First[A]] =
40-
Semigroup.instance((x, y) => x)
40+
Semigroup.inst((x, y) => x)
4141
}
4242

4343
opaque type Last[A] = A
4444
object Last extends Wrapper[Last] { // error: object creation impossible
4545
def wraps[G[_], A](ga: G[A]): G[Last[A]] = ga // error: overriding
4646
def unwrap[G[_], A](gfa: G[Last[A]]): G[A] = gfa
4747
implicit def lastSemigroup[A]: Semigroup[Last[A]] =
48-
Semigroup.instance((x, y) => y)
48+
Semigroup.inst((x, y) => y)
4949
}
5050
}

tests/pos/opaque-groups.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package object groups {
44
}
55

66
object Semigroup {
7-
def instance[A](f: (A, A) => A): Semigroup[A] =
7+
def inst[A](f: (A, A) => A): Semigroup[A] =
88
new Semigroup[A] {
99
def combine(x: A, y: A): A = f(x, y)
1010
}
@@ -36,7 +36,7 @@ package object groups {
3636
def wraps[G[_], A](ga: G[A]): G[First[A]] = ga
3737
def unwrap[G[_], A](gfa: G[First[A]]): G[A] = gfa
3838
implicit def firstSemigroup[A]: Semigroup[First[A]] =
39-
Semigroup.instance((x, y) => x)
39+
Semigroup.inst((x, y) => x)
4040
}
4141

4242
opaque type Last[A] = A
@@ -45,7 +45,7 @@ package object groups {
4545
def wraps[G[_], A](ga: G[A]): G[Last[A]] = ga
4646
def unwrap[G[_], A](gfa: G[Last[A]]): G[A] = gfa
4747
implicit def lastSemigroup[A]: Semigroup[Last[A]] =
48-
Semigroup.instance((x, y) => y)
48+
Semigroup.inst((x, y) => y)
4949
}
5050

5151
opaque type Min[A] = A
@@ -54,7 +54,7 @@ package object groups {
5454
def wraps[G[_], A](ga: G[A]): G[Min[A]] = ga
5555
def unwrap[G[_], A](gfa: G[Min[A]]): G[A] = gfa
5656
implicit def minSemigroup[A](implicit o: Ordering[A]): Semigroup[Min[A]] =
57-
Semigroup.instance(o.min)
57+
Semigroup.inst(o.min)
5858
}
5959

6060
opaque type Max[A] = A
@@ -63,7 +63,7 @@ package object groups {
6363
def wraps[G[_], A](ga: G[A]): G[Max[A]] = ga
6464
def unwrap[G[_], A](gfa: G[Max[A]]): G[A] = gfa
6565
implicit def maxSemigroup[A](implicit o: Ordering[A]): Semigroup[Max[A]] =
66-
Semigroup.instance(o.max)
66+
Semigroup.inst(o.max)
6767
}
6868

6969
opaque type Plus[A] = A
@@ -72,7 +72,7 @@ package object groups {
7272
def wraps[G[_], A](ga: G[A]): G[Plus[A]] = ga
7373
def unwrap[G[_], A](gfa: G[Plus[A]]): G[A] = gfa
7474
implicit def plusSemigroup[A](implicit n: Numeric[A]): Semigroup[Plus[A]] =
75-
Semigroup.instance(n.plus)
75+
Semigroup.inst(n.plus)
7676
}
7777

7878
opaque type Times[A] = A
@@ -81,7 +81,7 @@ package object groups {
8181
def wraps[G[_], A](ga: G[A]): G[Times[A]] = ga
8282
def unwrap[G[_], A](gfa: G[Times[A]]): G[A] = gfa
8383
implicit def timesSemigroup[A](implicit n: Numeric[A]): Semigroup[Times[A]] =
84-
Semigroup.instance(n.times)
84+
Semigroup.inst(n.times)
8585
}
8686

8787
opaque type Reversed[A] = A

tests/pos/phantom-Evidence.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ object WithNormalState {
1515
}
1616

1717
def run() = {
18-
val instance = Instance.newInstance()
19-
instance.getOnInstance // inferred phantom evidence parameter =::= is erased
20-
instance.getOnInstance.getOffInstance.getOnInstance.getOffInstance // all inferred phantom evidence parameters =::= are erased
18+
val inst = Instance.newInstance()
19+
inst.getOnInstance // inferred phantom evidence parameter =::= is erased
20+
inst.getOnInstance.getOffInstance.getOnInstance.getOffInstance // all inferred phantom evidence parameters =::= are erased
2121
}
2222

2323
}

tests/pos/t7753.scala

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ import scala.language.{ higherKinds, implicitConversions }
33
trait Foo { type Out }
44

55
trait SI {
6-
val instance: Foo
6+
val inst: Foo
77
type Out
88
}
99

1010
object Test {
1111
def test: Unit = {
12-
def indirect(si: SI)(v: si.instance.Out) = v
12+
def indirect(si: SI)(v: si.inst.Out) = v
1313

1414
val foo: Foo { type Out = Int } = ???
15-
def conv(i: Foo): SI { type Out = i.Out; val instance: i.type } = ???
15+
def conv(i: Foo): SI { type Out = i.Out; val inst: i.type } = ???
1616

1717
val converted = conv(foo)
1818

19-
val v1: Int = indirect(converted)(23) // Okay (after refining the return type `instance` in the return type of `conv`)
19+
val v1: Int = indirect(converted)(23) // Okay (after refining the return type `inst` in the return type of `conv`)
2020
/*
21-
indirect(converted){(v: converted.instance.Out)converted.instance.Out}(
21+
indirect(converted){(v: converted.inst.Out)converted.inst.Out}(
2222
23{Int(23)}
23-
){converted.instance.Out};
23+
){converted.inst.Out};
2424
*/
2525

2626
val v2: Int = indirect(conv(foo))(23) // Used to fail as follows:
2727
/*
2828
indirect(
29-
conv(foo){si.SI{type Out = foo.Out; val instance: si.Test.<refinement>.type}}
30-
){(v: si.instance.Out)si.instance.Out}(
29+
conv(foo){si.SI{type Out = foo.Out; val inst: si.Test.<refinement>.type}}
30+
){(v: si.inst.Out)si.inst.Out}(
3131
23{<error>}
3232
){<error>};
3333
*/

tests/pos/typeclass-encoding.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
}
2020
2121
def sum[T: Monoid](xs: List[T]): T =
22-
(instance[T, Monoid].unit /: xs)(_ `add` _)
22+
(inst[T, Monoid].unit /: xs)(_ `add` _)
2323
2424
*/
2525
object runtime {
@@ -37,7 +37,7 @@ object runtime {
3737

3838
class CompanionOf[T] { type StaticPart[_] }
3939

40-
def instance[From, To <: TypeClass](
40+
def inst[From, To <: TypeClass](
4141
implicit ev1: Implementation[From] { type Implemented = To },
4242
ev2: CompanionOf[To]): Implementation[From] { type Implemented = To } & ev2.StaticPart[From] =
4343
ev1.asInstanceOf // can we avoid the cast?
@@ -85,7 +85,7 @@ object semiGroups {
8585
}
8686

8787
def sum[T](xs: List[T])(implicit $ev: Implementation[T] { type Implemented = Monoid } ) = {
88-
(instance[T, Monoid].unit /: xs)((x, y) => inject(x) `add` y)
89-
(instance[T, Monoid].unit /: xs)((x, y) => x `add` y) // fails in scalac and previous dotc.
88+
(inst[T, Monoid].unit /: xs)((x, y) => inject(x) `add` y)
89+
(inst[T, Monoid].unit /: xs)((x, y) => x `add` y) // fails in scalac and previous dotc.
9090
}
9191
}

tests/run/try.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ object Test extends AnyRef with App {
3838
Console.println(x + n);
3939
}
4040

41-
var instance: AnyRef = null;
41+
var inst: AnyRef = null;
4242

4343
def try4 = {
44-
if (instance == null) {
45-
instance = try {
44+
if (inst == null) {
45+
inst = try {
4646
"" //new String();
4747
} catch {
4848
case _: Throwable =>

0 commit comments

Comments
 (0)