Coder Social home page Coder Social logo

Comments (8)

ilyapuchka avatar ilyapuchka commented on May 21, 2024 1

That's exactly what I'm doing now 😉

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

Hi @bejar37. Can you provide an example of your enum?

from sourcery.

bejar37 avatar bejar37 commented on May 21, 2024

sure, just tried with this:

enum IntOrString: AutoEnumDecodable {
    case s(string: String)
    case i(int: Int)
}

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

There is clearly an issue with detecting enum rawValue type. Currently parser assumes that the first type after ":" is a RawType, which is wrong when you just conform to protocol. Will try to fix that.

from sourcery.

bejar37 avatar bejar37 commented on May 21, 2024

Ah, that seems reasonable! I wouldn't mind doing:

enum IntOrString {
    case s(string: String)
    case i(int: Int)
}
extension IntOrString: AutoEnumEncodable { }

But this doesn't work either. That's probably the same as #35 ?

from sourcery.

ilyapuchka avatar ilyapuchka commented on May 21, 2024

I'm afraid even with #35 fixed we need to make some fixes for that problem too. I'm currently looking for solutions.

from sourcery.

krzysztofzablocki avatar krzysztofzablocki commented on May 21, 2024

I think if we waited with rawType resolution until uniqueTypes gets called then we can resolve this because we can identify whether a type is a protocol, class, struct etc. what do you think @ilyapuchka ?

from sourcery.

jpeckner avatar jpeckner commented on May 21, 2024

@ilyapuchka @krzysztofzablocki I'm still seeing this issue using 0.16.1. I have protocol MyAutoCellType in a framework that my app target is linked to, and enum MyTestEnum in my app target. MyAutoCellType only gets recognized by Sourcery templates if it's not the first conformance declared on a enum (or, if I temporarily move MyAutoCellType into my app target itself, this issue goes away, but I need to avoid that option).

For example, Sourcery sees the MyAutoCellType conformance here:

enum MyTestEnum: Equatable, MyAutoCellType {
    // sourcery: cellType = "MyTableViewCell"
    case test
}

and here:

enum MyTestEnum: String, MyAutoCellType {
    // sourcery: cellType = "MyTableViewCell"
    case test
}

but not here:

enum MyTestEnum: MyAutoCellType {
    // sourcery: cellType = "MyTableViewCell"
    case test
}

and not here:

enum MyTestEnum: MyAutoCellType, Equatable {
    // sourcery: cellType = "MyTableViewCell"
    case test
}

I verified this by adding the following dump to my template. With the first two examples, the dump has inheritedTypes = ["MyAutoCellType"], but with the last two, inheritedTypes doesn't contain "MyAutoCellType".

{% for type in types.enums where type.localName == "MyTestEnum" %}
// {{ type }}
{% endfor %}

I did find that declaring the protocol conformance on an extension (i.e. extension MyTestEnum: MyAutoCellType) gets Sourcery to recognize the conformance. So given that there are at least two workarounds for this problem (either putting another declaration in front of your custom protocol; or using an extension), it might not be a high-priority bug, but FYI that it's still out there.

from sourcery.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.