If statement returned in a closure - Internal compiler error #995
brian
25 Feb 2010
Promoted to ticket #995 and assigned to brian
There is some bug in the compiler there.
You can't use return in it-block to be make it crystal clear what you are returning from (we've had some previous discussions on that topic). So if you want to use return then you need to use normal closure syntax.
katox
25 Feb 2010
You can't use return in it-block to be make it crystal clear what you are returning from
I wasn't sure if it wasn't due to some nasty case. Thanks for reminding me. Also, I'm glad that we don't have non-local returns - the more I'm getting used to closures the less I like that idea.
brian
23 Mar 2010
Ticket resolved in 1.0.52
Fixed ClosureExpr.collapseExprAndReturn to ignore non-return statements
katox
25 Feb 2010
I found out that
internal XElem? findFront(XElem e) { frontmatter := e.elems.eachWhile |x| { log.debug ("name=${x.name}") // without this line it compiles OK if (x.name == "frontmatter") return x else return findFront(x) } return frontmatter }causes an internal compiler error (mercurial tip):
If rewritten as
internal XElem? findFront(XElem e) { frontmatter := e.elems.eachWhile |x| { log.debug ("name=${x.name}") return x.name == "frontmatter" ? x : findFront(x) } return frontmatter }it works fine.
Sidenote: What was the reason disallowing
returninit-blocks? No big issue but it behaves a bit strangely. Going fromfrontmatter := e.elems.eachWhile { it.name == "frontmatter" ? it : findFront(it) // ok }which compiles fine to a debugging version of
frontmatter := e.elems.eachWhile { log.debug ("name=${it.name}") it.name == "frontmatter" ? it : findFront(it) // nonexpr, missing return }the compiler complains of
Must return a value from non-Void methodbutreturnis not allowed here so one have to rewrite everything asfrontmatter := e.elems.eachWhile |x| { log.debug ("name=${x.name}") return x.name == "frontmatter" ? x : findFront(x) // return ok }