New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boolean xs:element (minOccurs=1) with default value produces bad code #245

Closed
alboko opened this Issue Apr 14, 2014 · 3 comments

Comments

Projects
None yet
2 participants
@alboko

alboko commented Apr 14, 2014

steps

            <xsd:element name="ParseItineraries" type="xsd:boolean" nillable="true" default="false">
                <xsd:annotation>
                    <xsd:documentation>Parse and return user itineraries</xsd:documentation>
                </xsd:annotation>
            </xsd:element>

compile a schema that has nillable boolean with a default value.

$ git clone git@github.com:alboko/aw-scalaxb-test.git 
$ cd aw-scalaxb-test
$ git co f2ff35ce5fdda94a196ef051b574495cff21cec4 -b topic/repro

problem

[info] Compiling 10 Scala sources to /aw-scalaxb-test/target/scala-2.10/classes...
[error] /aw-scalaxb-test/target/scala-2.10/src_managed/main/sbt-scalaxb/aw/xmlprotocol.scala:630: type mismatch;
[error]  found   : Boolean
[error]  required: Option[Boolean]
[error]         p2.headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) },
[error]                                                                                                                                ^
[error] one error found
[error] (compile:compile) Compilation failed

original report

Hello,

I'm getting a compilation error in xmlprotocol.scala generated by latest scalaxb (1.1.2) from a large WSDL file:

[info] Compiling 10 Scala sources to /aw-scalaxb-test/target/scala-2.10/classes...
[error] /aw-scalaxb-test/target/scala-2.10/src_managed/main/sbt-scalaxb/aw/xmlprotocol.scala:630: type mismatch;
[error]  found   : Boolean
[error]  required: Option[Boolean]
[error]         p2.headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) },
[error]                                                                                                                                ^
[error] one error found
[error] (compile:compile) Compilation failed

Here is a corresponding piece of code (the error is on first "p2.headOption map" line):

(scalaxb.ElemName(None, "HistoryVersion")) ~ 
      (scalaxb.ElemName(None, "HistoryLastDate"))) ^^ 
        { case p1 ~ p2 ~ p3 ~ p4 ~ p5 ~ p6 ~ p7 ~ p8 ~ p9 ~ p10 => aw.CheckAccountRequestSequence2(p1.nilOption map { scalaxb.fromXML[Int](_, scalaxb.ElemName(node) :: stack) },
        p2.headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) },
        p3.nilOption map { scalaxb.fromXML[String](_, scalaxb.ElemName(node) :: stack) },
        p4.nilOption map { scalaxb.fromXML[String](_, scalaxb.ElemName(node) :: stack) },
        p5.toSeq map { _.nilOption map { scalaxb.fromXML[aw.MarkUsedCouponType](_, scalaxb.ElemName(node) :: stack) }},
        p6.toSeq map { scalaxb.fromXML[aw.AnswerType](_, scalaxb.ElemName(node) :: stack) },
        p7.nilOption map { scalaxb.fromXML[String](_, scalaxb.ElemName(node) :: stack) },
        p8.headOption map { scalaxb.fromXML[Boolean](_, scalaxb.ElemName(node) :: stack) } getOrElse { scalaxb.fromXML[Boolean](scala.xml.Text("false"), scalaxb.ElemName(node) :: stack) },
        p9.nilOption map { scalaxb.fromXML[Int](_, scalaxb.ElemName(node) :: stack) },
        p10.nilOption map { scalaxb.fromXML[javax.xml.datatype.XMLGregorianCalendar](_, scalaxb.ElemName(node) :: stack) }) }) ~ 
      (((scalaxb.ElemName(None, "ParseFiles")) ~ 
      (scalaxb.ElemName(None, "FilesVersion")) ~ 

The error seems strange to me since there are several very similar constructions in the code around. Are all of them generated wrong?

Can anyone give me a hint what is wrong here?

Original WSDL and all code is in my github project: https://github.com/alboko/aw-scalaxb-test

Thanks,
Alex

@alboko

This comment has been minimized.

Show comment
Hide comment
@alboko

alboko Apr 15, 2014

A similar error message appears in recently fixed #229 . However, I tried the latest SNAPSHOT and the compilation still fails.

alboko commented Apr 15, 2014

A similar error message appears in recently fixed #229 . However, I tried the latest SNAPSHOT and the compilation still fails.

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Apr 15, 2014

Owner

This is likely a bug in scalaxb.

Owner

eed3si9n commented Apr 15, 2014

This is likely a bug in scalaxb.

alboko pushed a commit to alboko/aw-scalaxb-test that referenced this issue Apr 15, 2014

@eed3si9n eed3si9n changed the title from compilation error in generated xmlprotocol.scala - found: Boolean, required: Option[Boolean] to nillable boolean with default value produces bad code Jun 9, 2014

@eed3si9n eed3si9n added the bug label Jun 9, 2014

@eed3si9n eed3si9n added this to the 1.2.0 milestone Jun 14, 2014

@eed3si9n eed3si9n changed the title from nillable boolean with default value produces bad code to boolean xs:element (minOccurs=1) with default value produces bad code Jun 14, 2014

@eed3si9n

This comment has been minimized.

Show comment
Hide comment
@eed3si9n

eed3si9n Jun 14, 2014

Owner

3.3.1 The Element Declaration Schema Component:

{value constraint} establishes a default or fixed value for an element. If default is specified, and if the element being validated is empty, then the canonical form of the supplied constraint value becomes the schema normalized value of the validated element in the post-schema-validation infoset. If fixed is specified, then the element's content must either be empty, in which case fixed behaves as default, or its value must match the supplied constraint value.

Owner

eed3si9n commented Jun 14, 2014

3.3.1 The Element Declaration Schema Component:

{value constraint} establishes a default or fixed value for an element. If default is specified, and if the element being validated is empty, then the canonical form of the supplied constraint value becomes the schema normalized value of the validated element in the post-schema-validation infoset. If fixed is specified, then the element's content must either be empty, in which case fixed behaves as default, or its value must match the supplied constraint value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment