Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala's wrong forward reference error

private def foo(a:A):B = a match{
    case A(...) =>
        val x = a.b //error: wrong forward reference a
        ...
}

Where b is not mentioned in A(...), if that matters.

I've tried my luck on Google, but I seem to find only posts of people having errors involving forward references but no explanation of what this particular error actually means.

Would appreciate it if somebody could help me out.

like image 335
User1291 Avatar asked Mar 26 '15 08:03

User1291


1 Answers

Well, don't I feel stupid now...

private def foo(a:A):B = a match{
    case A(...) =>
        val x = a.b //error: wrong forward reference a
        ...
        val a = ... //<-- THAT's the reason for the error
        ...
}

So a simple rename will resolve the issue:

private def foo(aa:A):B = aa match{
    case A(...) =>
        val x = aa.b
        ...
        val a = ...
        ...
}
like image 185
User1291 Avatar answered Sep 25 '22 05:09

User1291