Skip to content

Enum: fixed #4269, work fine with private#4314

Closed
makenowjust wants to merge 1 commit intocrystal-lang:masterfrom
makenowjust:fix/enum/private
Closed

Enum: fixed #4269, work fine with private#4314
makenowjust wants to merge 1 commit intocrystal-lang:masterfrom
makenowjust:fix/enum/private

Conversation

@makenowjust
Copy link
Contributor

Fixed #4269.

Use new({{@type.constant member}}) instead of {{@type}}::{{member}}. It works fine. However I think, Enum.flags macro cannot implement correctly on current Crystal compiler.

@bcardiff
Copy link
Member

bcardiff commented May 4, 2017

The expanded code is not that nice since it use the values of the enum instead of their name.
It's great that we can fix enum at least, but I would prefer a more general solution that could be applied to any private type.

But it is a clever workaround.

@sdogruyol
Copy link
Member

Can we merge this for now and add a TODO for a better version in the future?

@asterite
Copy link
Member

I think private types were a mistake, mostly because of problems like this one. private methods are fine, though. So I'll close this and then propose removing private types from the language.

@asterite asterite closed this Sep 29, 2017
@makenowjust makenowjust deleted the fix/enum/private branch September 29, 2017 14:42
@makenowjust
Copy link
Contributor Author

@asterite I don't think private types are evil. Crystal has no access control over package and string based macro is wrong. Crystal features are not enough to use private types comfortably.

@asterite
Copy link
Member

They are not evil, they just don't work well with other features. That means they weren't thought through, and it's better to remove them than to have a broken feature. Also Ruby and Python don't have visibility modifiers for types and they work fine.

@bcardiff
Copy link
Member

I think private types should just have a name that the user won't be able to type and make it imposible to reopen outside the file. With that the metaprograming type expansion will work. I see them as like annonymous type of other languages.

At the end of the day private methods are also obfuscated method names.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants