0

I'm running into a compiler problem when using Scala7-M9 and json4s 3.0.1 with compiler versions 2.10.0 and 2.10.1

When compiling the short snippet of JSON parsing code, I get the following compiler error:

[error] JSON.scala:25: erroneous or inaccessible type
[error]                 JArray(children) <- json \ "children"
[error]                                          ^

from this code:

import scalaz._                                                                 
import Scalaz._                                                                 

import org.json4s._                                                             
import org.json4s.native.JsonMethods._                                          

object JSON {                                                                   

    def main(args: Array[String]) = {                                           
        val json = parse("""                                                    
            {   "name": "joe",                                                  
                "children": [                                                   
                    {                                                           
                        "name": "Mary",                                         
                        "age": 5                                                
                    },                                                          
                    {                                                           
                        "name": "Mazy",                                         
                        "age": 3                                                
                    }]                                                          
            } """)                                                              

        val names = for {                                                       
                JArray(children) <- json \ "children"                           
                JObject(child) <- children                                      
                JField("name", JString(name)) <- child                          
             } yield(name)                                                       

        println("Names: " + names)                                              
     }                                                                           
 }

Changing the imports to:

 import scalaz.{Scalaz, \/}                                                                    
 import Scalaz.ToIdOps._

(in my real project I only need the / monad for some validation) fixes the issue.

Just wondering if anyone from the Scalaz/compiler world would have an idea what was causing the compiler error when I import the whole scalaz namespace and if it's a BUG I need to file.

Thanks.

JMac
  • 549
  • 1
  • 6
  • 16
  • 1
    https://issues.scala-lang.org/browse/SI-6865 – Kenji Yoshida Mar 25 '13 at 03:07
  • @Kenji Thanks; I guess I'll have to wait for a fix or just attempt to use work arounds till it's fixed. – JMac Mar 25 '13 at 03:26
  • 1
    By the way (not question-related, but still), `Scalaz._` import is deprecated in `scalaz-seven`. You are expected to use the a-la-carte imports. In this case, I believe it would be something like `import scalaz._, syntax.id._`. – George Mar 25 '13 at 08:31
  • @folone Thanks, I'm still transitioning :) It's a bit difficult to know which package to import sometimes, little to no documentation. – JMac Mar 26 '13 at 22:54

0 Answers0