Skip to content

Commit 3f3a3bb

Browse files
committed
SI-9245 Fresher name in Try and test
Fresh name for catcher gets a dollar. "Here, have a dollar." Test due to retronym demonstrates possible conflict. Over the lifetime of the universe, surely at least one code monkey would type in that identifier to catch a banana.
1 parent 650fbee commit 3f3a3bb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ abstract class TreeBuilder {
105105
def makeCatchFromExpr(catchExpr: Tree): CaseDef = {
106106
val binder = freshTermName()
107107
val pat = Bind(binder, Typed(Ident(nme.WILDCARD), Ident(tpnme.Throwable)))
108-
val catchDef = ValDef(Modifiers(ARTIFACT), freshTermName("catchExpr"), TypeTree(), catchExpr)
108+
val catchDef = ValDef(Modifiers(ARTIFACT), freshTermName("catchExpr$"), TypeTree(), catchExpr)
109109
val catchFn = Ident(catchDef.name)
110110
val body = atPos(catchExpr.pos.makeTransparent)(Block(
111111
List(catchDef),

test/files/pos/t9245.scala

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
2+
/*
3+
Was:
4+
test/files/pos/t9245.scala:5: error: recursive value catchExpr1 needs type
5+
try {} catch catchExpr1
6+
^
7+
8+
Now:
9+
def catchExpr1: PartialFunction[Throwable,Any] = scala.this.Predef.???;
10+
def test: Any = try {
11+
()
12+
} catch {
13+
case (x$1 @ (_: Throwable)) => {
14+
<artifact> val catchExpr$1: PartialFunction[Throwable,Any] = Test.this.catchExpr1;
15+
if (catchExpr$1.isDefinedAt(x$1))
16+
catchExpr$1.apply(x$1)
17+
else
18+
throw x$1
19+
}
20+
}
21+
*/
22+
trait Test {
23+
def catchExpr1: PartialFunction[Throwable, Any] = ???
24+
def test = {
25+
try {} catch catchExpr1
26+
}
27+
}

0 commit comments

Comments
 (0)