Skip to content
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

Compilation error for type references inside a complex type #28

Open
andreivasiliu opened this issue Jul 5, 2023 · 5 comments
Open
Labels
bug Something isn't working

Comments

@andreivasiliu
Copy link

andreivasiliu commented Jul 5, 2023

The following schema fails to compile:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           xmlns:tns="http://www.example.com/books"
           targetNamespace="http://www.example.com/books">

    <xs:complexType name="BookDetails">
        <xs:sequence>
            <xs:element name="Title" type="xs:string"/>
            <xs:element name="Author" type="xs:string"/>
            <xs:element name="Year" type="xs:int"/>
        </xs:sequence>
    </xs:complexType>

    <!-- Works! -->
    <xs:element name="Book1" type="tns:BookDetails"/>

    <!-- Crashes with:
      cannot find type `BookDetails` in this scope
      help: consider importing this struct: crate::types::BookDetails -->
    <xs:element name="Book2">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="details" type="tns:BookDetails"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

The error is:

error[E0412]: cannot find type `BookDetails` in this scope
 --> src/main.rs:3:17
  |
3 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^ not found in this scope
  |
  = help: consider importing this struct:
          crate::types::BookDetails

Most likely the code generator for complex types is creating a new scope/module but it doesn't use super::* or something similar.

@andreivasiliu
Copy link
Author

andreivasiliu commented Jul 5, 2023

Using cargo expand, I got the following bits:

#[yaserde(
    prefix = "my_prefix",
    namespace = "my_prefix: http://www.example.com/books"
)]
pub struct Book1 {
    #[yaserde(flatten)]
    pub content: types::BookDetails,
}
#[yaserde(
    prefix = "my_prefix",
    namespace = "my_prefix: http://www.example.com/books"
)]
pub struct Book2 {
    #[yaserde(rename = "details", prefix = "my_prefix")]
    pub details: BookDetails,
}

The second reference to BookDetails, which does not have the types:: prefix, is probably one of the places where this is an issue.

@Masken8
Copy link

Masken8 commented Dec 16, 2023

I'm having the same issue.

@MarcAntoine-Arnaud
Copy link
Contributor

Hi @andreivasiliu @Masken8

I have updated the code on main that fix the problem.

Can you check if it fix it correctly ?

@MarcAntoine-Arnaud MarcAntoine-Arnaud added the bug Something isn't working label Dec 18, 2023
@andreivasiliu
Copy link
Author

Something's different now, but it does not compile... at least assuming I'm supposed to use it the same way as before, and nothing changed on what I need to use.

error[E0433]: failed to resolve: use of undeclared crate or module `xml_schema_types`
 --> src/main.rs:3:17
  |
3 | #[derive(Debug, XmlSchema)]
  |                 ^^^^^^^^^ use of undeclared crate or module `xml_schema_types`
  |
  = help: consider importing this module through its public re-export:
          crate::xml_schema_types
  = note: this error originates in the derive macro `XmlSchema` (in Nightly builds, run with -Z macro-backtrace for more info)

This xml_schema_types seems to be created by the macro inside my own crate, so I doubt I need to import it myself.

This is what I used:
https://gist.github.com/andreivasiliu/cde0a669d75bb2d80ae1f6acd92d5263

@MarcAntoine-Arnaud
Copy link
Contributor

MarcAntoine-Arnaud commented Dec 19, 2023

Hi @andreivasiliu
The code compiles correctly, you have changed the initial XSD.

I have generated a fix to handle this case.

Let me know if it's fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants