Giter Club home page Giter Club logo

Comments (5)

Blacksmoke16 avatar Blacksmoke16 commented on June 18, 2024 2

I guess you could argue it both ways. It's not a bug because this feature requires explicit type restrictions to work, but an enhancement could be to make it smarter in cases like this. But in either case it's usually a good practice to use type restrictions, so then you could also argue this is a case of "just be explicit and it works" or at least low on the priority list.

from crystal.

ysbaddaden avatar ysbaddaden commented on June 18, 2024 1

This is two-fold:

  1. casting a symbol to an enum requires the argument's type to be explicit (value : MyEnum).
  2. def method(@value); end gets transformed to def method(value) @value = value; end in which case the value argument becomes typeless.

Now, a feature enhancement could be for the ivar expansion in methods to automatically include the ivar type. I'd love it, though I'm not sure how easy or hard it would be to implement, especially if we expand the syntax before we start inferring the ivar types (we don't want to bring event more confusion by having some ivar arguments typed while others are not.

So: this isn't a bug but a potential enhancement.

from crystal.

Blacksmoke16 avatar Blacksmoke16 commented on June 18, 2024

Don't quote me on this, but I'm guessing that the compiler doesn't really have an explicit type on the @en var as it would be inherited from the parent type. Symbol to enum autocasting requires the explicit type restrictions. I.e. if you do @en : MyEnum on the child initializer, it'll work fine.

So this may be more of a feature/enhancement request versus an actual bug?

from crystal.

devnote-dev avatar devnote-dev commented on June 18, 2024

I'd say it's more a bug because I don't know why you'd want this as a feature, and instance variable inheritance is confusing enough as it is...

from crystal.

straight-shoota avatar straight-shoota commented on June 18, 2024

I don't think it should be too difficult. When expanding an ivar paramter name, we can copy the ivar's type restriction to the parameter. That should make it work.

from crystal.

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.