Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit 48590fe

Browse files
committed
Merge pull request #8 from adriaanm/master
Use context for error reporting.
2 parents 2de25d3 + 76bef2e commit 48590fe

File tree

6 files changed

+24
-25
lines changed

6 files changed

+24
-25
lines changed

build.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ lazy val commonSettings = scalaModuleSettings ++ Seq(
88
repoName := "scala-continuations",
99
organization := "org.scala-lang.plugins",
1010
version := "1.0.1-SNAPSHOT",
11-
scalaVersion := "2.11.0-RC1",
12-
snapshotScalaBinaryVersion := "2.11.0-RC1"
11+
scalaVersion := "2.11.1",
12+
snapshotScalaBinaryVersion := "2.11.1"
1313
)
1414

1515
lazy val root = project.in( file(".") ).settings( publishArtifact := false ).aggregate(plugin, library).settings(commonSettings : _*)

plugin/src/main/scala/scala/tools/selectivecps/CPSAnnotationChecker.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
399399
if (!cpsEnabled) {
400400
val report = try hasCpsParamTypes(tpe) catch { case _: MissingRequirementError => false }
401401
if (report)
402-
global.reporter.error(tree.pos, "this code must be compiled with the Scala continuations plugin enabled")
402+
reporter.error(tree.pos, "this code must be compiled with the Scala continuations plugin enabled")
403403

404404
return tpe
405405
}
@@ -488,7 +488,7 @@ abstract class CPSAnnotationChecker extends CPSUtils {
488488
if (!(atp0 =:= atp1))
489489
throw new TypeError("only simple cps types allowed in try/catch blocks (found: " + tpe1 + ")")
490490
if (!finalizer.isEmpty) // no finalizers allowed. see explanation in SelectiveCPSTransform
491-
reporter.error(tree.pos, "try/catch blocks that use continuations cannot have finalizers")
491+
typer.context.error(tree.pos, "try/catch blocks that use continuations cannot have finalizers")
492492
}
493493
tpe1
494494

plugin/src/main/scala/scala/tools/selectivecps/CPSUtils.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,12 @@ trait CPSUtils {
119119

120120
type CPSInfo = Option[(Type,Type)]
121121

122-
def linearize(a: CPSInfo, b: CPSInfo)(implicit unit: CompilationUnit, pos: Position): CPSInfo = {
122+
def linearize(a: CPSInfo, b: CPSInfo)(implicit pos: Position): CPSInfo = {
123123
(a,b) match {
124124
case (Some((u0,v0)), Some((u1,v1))) =>
125125
vprintln("check lin " + a + " andThen " + b)
126126
if (!(v1 <:< u0)) {
127-
unit.error(pos,"cannot change answer type in composition of cps expressions " +
127+
reporter.error(pos,"cannot change answer type in composition of cps expressions " +
128128
"from " + u1 + " to " + v0 + " because " + v1 + " is not a subtype of " + u0 + ".")
129129
throw new Exception("check lin " + a + " andThen " + b)
130130
}

plugin/src/main/scala/scala/tools/selectivecps/SelectiveANFTransform.scala

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
2727

2828
class ANFTransformer(unit: CompilationUnit) extends TypingTransformer(unit) {
2929

30-
implicit val _unit = unit // allow code in CPSUtils.scala to report errors
3130
var cpsAllowed: Boolean = false // detect cps code in places we do not handle (yet)
3231

3332
object RemoveTailReturnsTransformer extends Transformer {
@@ -63,7 +62,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
6362
treeCopy.CaseDef(tree, pat, guard, transform(body))
6463

6564
case Return(_) =>
66-
unit.error(tree.pos, "return expressions in CPS code must be in tail position")
65+
reporter.error(tree.pos, "return expressions in CPS code must be in tail position")
6766
tree
6867

6968
case _ =>
@@ -178,7 +177,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
178177
treeCopy.ValDef(vd, mods, name, transform(tpt), rhs1)
179178
}
180179
} else {
181-
unit.error(tree.pos, "cps annotations not allowed on by-value parameters or value definitions")
180+
reporter.error(tree.pos, "cps annotations not allowed on by-value parameters or value definitions")
182181
super.transform(tree)
183182
}
184183

@@ -195,9 +194,9 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
195194
if (hasAnswerTypeAnn(tree.tpe)) {
196195
if (!cpsAllowed) {
197196
if (tree.symbol.isLazy)
198-
unit.error(tree.pos, "implementation restriction: cps annotations not allowed on lazy value definitions")
197+
reporter.error(tree.pos, "implementation restriction: cps annotations not allowed on lazy value definitions")
199198
else
200-
unit.error(tree.pos, "cps code not allowed here / " + tree.getClass + " / " + tree)
199+
reporter.error(tree.pos, "cps code not allowed here / " + tree.getClass + " / " + tree)
201200
}
202201
log(tree)
203202
}
@@ -268,10 +267,10 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
268267
// check that then and else parts agree (not necessary any more, but left as sanity check)
269268
if (cpsR.isDefined) {
270269
if (elsep == EmptyTree)
271-
unit.error(tree.pos, "always need else part in cps code")
270+
reporter.error(tree.pos, "always need else part in cps code")
272271
}
273272
if (hasAnswerTypeAnn(thenVal.tpe) != hasAnswerTypeAnn(elseVal.tpe)) {
274-
unit.error(tree.pos, "then and else parts must both be cps code or neither of them")
273+
reporter.error(tree.pos, "then and else parts must both be cps code or neither of them")
275274
}
276275

277276
(condStats, updateSynthFlag(treeCopy.If(tree, condVal, thenVal, elseVal)), spc)
@@ -341,7 +340,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
341340

342341
case Return(expr0) =>
343342
if (isAnyParentImpure)
344-
unit.error(tree.pos, "return expression not allowed, since method calls CPS method")
343+
reporter.error(tree.pos, "return expression not allowed, since method calls CPS method")
345344
val (stms, expr, spc) = transInlineValue(expr0, cpsA)
346345
(stms, updateSynthFlag(treeCopy.Return(tree, expr)), spc)
347346

@@ -384,7 +383,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
384383

385384
val (stms, expr, spc) = transValue(tree, cpsA, cpsR)
386385

387-
val bot = linearize(spc, getAnswerTypeAnn(expr.tpe))(unit, tree.pos)
386+
val bot = linearize(spc, getAnswerTypeAnn(expr.tpe))(tree.pos)
388387

389388
val plainTpe = removeAllCPSAnnotations(expr.tpe)
390389

@@ -425,13 +424,13 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
425424
// TODO - obviously this should be done earlier, differently, or with
426425
// a more skilled hand. Most likely, all three.
427426
if ((b.typeSymbol eq NothingClass) && call.tpe.exists(_ eq WildcardType))
428-
unit.error(tree.pos, "cannot cps-transform malformed (possibly in shift/reset placement) expression")
427+
reporter.error(tree.pos, "cannot cps-transform malformed (possibly in shift/reset placement) expression")
429428
else
430429
return ((stms, call))
431430
}
432431
catch {
433432
case ex:TypeError =>
434-
unit.error(ex.pos, "cannot cps-transform expression " + tree + ": " + ex.msg)
433+
reporter.error(ex.pos, "cannot cps-transform expression " + tree + ": " + ex.msg)
435434
}
436435
}
437436

@@ -442,7 +441,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
442441

443442
//println(cpsR + "/" + spc + "/" + bot)
444443

445-
unit.error(tree.pos, "found cps expression in non-cps position")
444+
reporter.error(tree.pos, "found cps expression in non-cps position")
446445
} else {
447446
// all is well
448447

@@ -474,7 +473,7 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
474473
expr.changeOwner(currentOwner -> sym)
475474

476475
(stms ::: List(ValDef(sym, expr) setType(NoType)),
477-
Ident(sym) setType(valueTpe) setPos(tree.pos), linearize(spc, spcVal)(unit, tree.pos))
476+
Ident(sym) setType(valueTpe) setPos(tree.pos), linearize(spc, spcVal)(tree.pos))
478477

479478
case _ =>
480479
(stms, expr, spc)
@@ -503,12 +502,12 @@ abstract class SelectiveANFTransform extends PluginComponent with Transform with
503502
val spcVal = getAnswerTypeAnn(anfRhs.tpe)
504503
spcVal foreach (_ => tree.symbol setAnnotations List(AnnotationInfo(MarkerCPSSym.tpe_*, Nil, Nil)))
505504

506-
(stms:::List(treeCopy.ValDef(tree, mods, name, tpt, anfRhs)), linearize(spc, spcVal)(unit, tree.pos))
505+
(stms:::List(treeCopy.ValDef(tree, mods, name, tpt, anfRhs)), linearize(spc, spcVal)(tree.pos))
507506

508507
case _ =>
509508
val (headStms, headExpr, headSpc) = transInlineValue(stm, cpsA)
510509
val valSpc = getAnswerTypeAnn(headExpr.tpe)
511-
(headStms:::List(headExpr), linearize(headSpc, valSpc)(unit, stm.pos))
510+
(headStms:::List(headExpr), linearize(headSpc, valSpc)(stm.pos))
512511
}
513512
}
514513

plugin/src/main/scala/scala/tools/selectivecps/SelectiveCPSTransform.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
293293
// of testing for Context
294294
if ((body2.tpe == null) || !(body2.tpe.typeSymbol == Context)) {
295295
//println(body2 + "/" + body2.tpe)
296-
unit.error(rhs.pos, "cannot compute type for CPS-transformed function result")
296+
reporter.error(rhs.pos, "cannot compute type for CPS-transformed function result")
297297
}
298298
body2
299299
}
@@ -321,7 +321,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
321321
methodName = nme.flatMap
322322
}
323323
else
324-
unit.error(rhs.pos, "cannot compute type for CPS-transformed function result")
324+
reporter.error(rhs.pos, "cannot compute type for CPS-transformed function result")
325325

326326
debuglog("will use method:"+methodName)
327327

@@ -366,7 +366,7 @@ abstract class SelectiveCPSTransform extends PluginComponent with
366366
}
367367
} catch {
368368
case ex:TypeError =>
369-
unit.error(ex.pos, ex.msg)
369+
reporter.error(ex.pos, ex.msg)
370370
(bodyStms, bodyExpr)
371371
}
372372

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.2
1+
sbt.version=0.13.5

0 commit comments

Comments
 (0)