Aladdin - Scala Bugtracking
[#834] project: compiler priority: medium category: bug
submitter assigned to status date submitted
Lex Martin fixed 2006-11-24 14:58:13.0
subject return in a closure in a method in a method
code
object Test {
  def response: String = {
    def check: Option[String] = {
      val closure: String=>Nothing =
        p => return Some("deep return") // should return from check

      closure("whatever")
    }

    check

    return "ok"
  }

  def main(args: Array[String]) {
    Console.println(response)
  }
}
what happened
exception when traversing def check: scala.Option[java.lang.String] = {
  val closure: (java.lang.String) => scala.Nothing = ((p: java.lang.String) => return new scala.Some[java.lang.S\
tring]("deep return"));
  closure.apply("whatever")
}
exception when traversing {
  def check: scala.Option[java.lang.String] = {
    val closure: (java.lang.String) => scala.Nothing = ((p: java.lang.String) => return new scala.Some[java.lang\
.String]("deep return"));
    closure.apply("whatever")
  };
  check;
  return "ok"
}
exception when traversing def response: java.lang.String = {
  def check: scala.Option[java.lang.String] = {
    val closure: (java.lang.String) => scala.Nothing = ((p: java.lang.String) => return new scala.Some[java.lang\
.String]("deep return"));
    closure.apply("whatever")
  };
  check;
  return "ok"
}
exception when traversing java.lang.Object with scala.ScalaObject {
  def this(): object Test = {
    Test.super.this();
    ()
  };
  def response: java.lang.String = {
    def check: scala.Option[java.lang.String] = {
      val closure: (java.lang.String) => scala.Nothing = ((p: java.lang.String) => return new scala.Some[java.la\
ng.String]("deep return"));
      closure.apply("whatever")
    };
    check;
    return "ok"
  };
  def main(args: scala.Array[java.lang.String]): scala.Unit = scala.Console.println(Test.this.response)
}
exception when traversing final class Test extends java.lang.Object with scala.ScalaObject {
  def this(): object Test = {
    Test.super.this();
    ()
  };
  def response: java.lang.String = {
    def check: scala.Option[java.lang.String] = {
      val closure: (java.lang.String) => scala.Nothing = ((p: java.lang.String) => return new scala.Some[java.la\
ng.String]("deep return"));
      closure.apply("whatever")
    };
    check;
    return "ok"
  };
  def main(args: scala.Array[java.lang.String]): scala.Unit = scala.Console.println(Test.this.response)
}
exception when traversing package  {
  final class Test extends java.lang.Object with scala.ScalaObject {
    def this(): object Test = {
      Test.super.this();
      ()
    };
    def response: java.lang.String = {
      def check: scala.Option[java.lang.String] = {
        val closure: (java.lang.String) => scala.Nothing = ((p: java.lang.String) => return new scala.Some[java.\
lang.String]("deep return"));
        closure.apply("whatever")
      };
      check;
      return "ok"
    };
    def main(args: scala.Array[java.lang.String]): scala.Unit = scala.Console.println(Test.this.response)
  }
}
Exception in thread "main" scala.tools.nsc.symtab.Types$TypeError: type _ escapes its defining scope as part of \
type _
	at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:252)
	at scala.tools.nsc.typechecker.Infer$Inferencer.error(Infer.scala:245)
	at scala.tools.nsc.typechecker.Typers$Typer$checkNoEscaping$.check(Typers.scala:338)
	at scala.tools.nsc.typechecker.Typers$Typer$checkNoEscaping$.locals(Typers.scala:318)
	at scala.tools.nsc.typechecker.Typers$Typer.typedCase(Typers.scala:1164)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$39.apply(Typers.scala:1171)
	at scala.tools.nsc.typechecker.Typers$Typer$$anonfun$39.apply(Typers.scala:1170)
	at scala.List$.loop$0(List.scala:244)
	at scala.List$.mapConserve(List.scala:261)
	at scala.tools.nsc.typechecker.Typers$Typer.typedCases(Typers.scala:1170)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1998)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2221)
	at scala.tools.nsc.typechecker.Typers$Typer.typedBlock(Typers.scala:1131)
	at scala.tools.nsc.typechecker.Typers$Typer.typed1(Typers.scala:1878)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2221)
	at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:2253)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.scala$tools$nsc$transform$UnCurry$UnCurryTransformer$$n\
onLocalReturnTry(UnCurry.scala:170)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer$$anonfun$17.apply(UnCurry.scala:437)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer$$anonfun$17.apply(UnCurry.scala:423)
	at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:77)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.postTransform(UnCurry.scala:423)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.transform(UnCurry.scala:95)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$30.apply(Trees.scala:1178)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$30.apply(Trees.scala:1176)
	at scala.List$.loop$0(List.scala:244)
	at scala.List$.mapConserve(List.scala:261)
	at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1176)
	at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1098)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:46)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.mainTransform(UnCurry.scala:415)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.transform(UnCurry.scala:95)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$20.apply(Trees.scala:1077)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$20.apply(Trees.scala:1076)
	at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1184)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:33)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:27)
	at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1075)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:46)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.scala$tools$nsc$transform$UnCurry$UnCurryTransformer$$s\
uper$transform(UnCurry.scala:345)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer$$anonfun$5.apply(UnCurry.scala:345)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer$$anonfun$5.apply(UnCurry.scala:329)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.withNeedLift$0(UnCurry.scala:313)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.mainTransform(UnCurry.scala:328)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.transform(UnCurry.scala:95)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$30.apply(Trees.scala:1178)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$30.apply(Trees.scala:1176)
	at scala.List$.loop$0(List.scala:244)
	at scala.List$.mapConserve(List.scala:261)
	at scala.List$.loop$0(List.scala:248)
	at scala.List$.mapConserve(List.scala:261)
	at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1176)
	at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1096)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$\
TypingTransformer$$super$transform(TypingTransformers.scala:44)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$0.apply(TypingTransformers.scala:44)\

	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$0.apply(TypingTransformers.scala:44)\

	at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1184)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:33)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:27)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:44)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.scala$tools$nsc$transform$UnCurry$UnCurryTransformer$$s\
uper$transform(UnCurry.scala:345)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer$$anonfun$16.apply(UnCurry.scala:412)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer$$anonfun$16.apply(UnCurry.scala:412)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.withInConstructorFlag$0(UnCurry.scala:321)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.mainTransform(UnCurry.scala:412)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.transform(UnCurry.scala:95)
	at scala.tools.nsc.ast.Trees$Transformer.transformTemplate(Trees.scala:1164)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$17.apply(Trees.scala:1064)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$17.apply(Trees.scala:1063)
	at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1184)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:33)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:27)
	at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1062)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:46)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.mainTransform(UnCurry.scala:415)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.transform(UnCurry.scala:95)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$30.apply(Trees.scala:1178)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$30.apply(Trees.scala:1176)
	at scala.List$.loop$0(List.scala:244)
	at scala.List$.mapConserve(List.scala:261)
	at scala.tools.nsc.ast.Trees$Transformer.transformStats(Trees.scala:1176)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$16.apply(Trees.scala:1059)
	at scala.tools.nsc.ast.Trees$Transformer$$anonfun$16.apply(Trees.scala:1059)
	at scala.tools.nsc.ast.Trees$Transformer.atOwner(Trees.scala:1184)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:33)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:27)
	at scala.tools.nsc.ast.Trees$Transformer.transform(Trees.scala:1058)
	at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:46)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.mainTransform(UnCurry.scala:415)
	at scala.tools.nsc.transform.UnCurry$UnCurryTransformer.transform(UnCurry.scala:95)
	at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:1179)
	at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
	at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:220)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:209)
	at scala.tools.nsc.Global$GlobalPhase$$anonfun$1.apply(Global.scala:209)
	at scala.Iterator$class.foreach(Iterator.scala:341)
	at scala.collection.mutable.ListBuffer$$anon$0.foreach(ListBuffer.scala:244)
	at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:209)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:475)
	at scala.tools.nsc.Global$Run.compile(Global.scala:547)
	at scala.tools.nsc.Main$.process(Main.scala:74)
	at scala.tools.nsc.Main$.main(Main.scala:96)
	at scala.tools.nsc.Main.main(Main.scala)
what expected This should compile and print "deep return"
[back to overview]
Changes of this bug report
Lex  edited on  2006-11-24 14:58:45.0
Lex  edited on  2006-11-24 15:01:55.0
Err, actually, this should print "ok", not "deep return". Anyway, this return should be allowed.
Martin  edited on  2006-11-27 15:15:21.0
The change in typed patterns triggered this, so this would probably affect all non-local returns, not just deep ones :-(