Comments (5)
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.
This is two-fold:
- casting a symbol to an enum requires the argument's type to be explicit (
value : MyEnum
). def method(@value); end
gets transformed todef method(value) @value = value; end
in which case thevalue
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.
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.
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.
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)
- Error when requesting administrator privileges on windows with powershell HOT 1
- "Error: can't use variable name 'foo' inside assignment to variable 'foo'" only applies to ternary statement HOT 1
- It's possible to create a Hash with duplicate keys using missing key block and update method HOT 2
- Formatter changes semantics when call is followed by space and `()` HOT 3
- Semantics of `Process.exec` on Windows
- When monkeypatching with `previous_def` with namespaced types in the method signature, that namespace seems to be missed
- `Hash#put_if_absent` can put duplicate keys
- `String#byte_index(Regex)`
- Allow space in cookie value for Set-Cookie header HOT 4
- `Enumerable(T)#to_a` regression with interface type HOT 5
- `previous_def` does not work with top-level funs HOT 1
- Macro blocks bleed scope HOT 1
- Incorrect formatting of multi-line macro expression with comment as first line
- Abstract def overload with free var
- Can't use Atomic with Int128 or UInt128 HOT 3
- When use crystal i with `wezterm`(a popular linux terminal), Alt + TAB will output controller character like [O[I [O[I into terminal. HOT 3
- Audit GH labels HOT 1
- Discrepancy in `String#rindex` for out-of-bound search offsets
- Invalid memory access when dynamically extending type
- invalid instruction when referencing overridden private interface types
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal.