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

Make the Refined constructor private[refined] #52

Closed
fthomas opened this issue Aug 9, 2015 · 2 comments
Closed

Make the Refined constructor private[refined] #52

fthomas opened this issue Aug 9, 2015 · 2 comments

Comments

@fthomas
Copy link
Owner

fthomas commented Aug 9, 2015

I'd like to make the constructor of Refined private[refined] to ensure that any Refined[T, P] values only contains Ts that satisfy P. But doing so currently fails a tut example:

[tut] *** Error reported at type_aliases.md:18
<console>:28: error: constructor Refined in class Refined cannot be accessed in object $iw
       Square('a', 1)
              ^

The reason for this is that the autoRefineV macro replaces 'a' with Refined('a') in this example and thus calling the constructor outside of the refined package. Can this be done without more black magic?

@fthomas
Copy link
Owner Author

fthomas commented Aug 10, 2015

One option is to add a (properly documented) public delegate for the private constructor with an ugly or scary name (e.g. unsafeApply) and use that in the macro implementation. This should ensure that nobody circumvents refineV and refineMV accidentally.

@fthomas
Copy link
Owner Author

fthomas commented Aug 10, 2015

Here is a relevant SO question: http://stackoverflow.com/questions/19170137/using-private-constructor-in-a-macro

Using an ugly named delegate seems to be the only option.

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

No branches or pull requests

1 participant