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

Support inline expressions in validators #6

Open
nettad opened this issue Feb 17, 2014 · 4 comments
Open

Support inline expressions in validators #6

nettad opened this issue Feb 17, 2014 · 4 comments
Assignees
Milestone

Comments

@nettad
Copy link

nettad commented Feb 17, 2014

validator[_] { s =>
  val foo = s.bar //assume bar is some list

   foo has size > 10
}

Obviously this is a simple irrelevant example but it doesn't compile.

@holograph holograph added this to the 0.3 milestone Feb 17, 2014
@holograph
Copy link
Contributor

The transformation macro currently assumes that every expression in the validation block is a validation rule (i.e. typechecks to Validator[_]), and needs to be rewritten to be able to reorder such a block to a (list of statements; list of validators) tuple. Seems like a worthwhile endeavor, adding to 0.3 milestone roadmap.

@holograph holograph self-assigned this Feb 17, 2014
@holograph
Copy link
Contributor

I've written a proof-of-concept implementation on a separate branch, you can see the relevant tests here (the bottom Interleaving object).

It's currently severely limited in that it assumes ordering and doesn't do escape analysis; in simple terms, each validator "tacks on" the preceding code lines. This means something like val something = ...; something is notNull; something is notEmpty will not work because the second rule won't "get" the free code ranges.

I need to do some further research into the macro context/compiler architecture to see if it's feasible to do some sort of escape analysis to figure out which snippets of code are necessary for each validator; it's possible that the Async extensions for Scala have already solved this.

@nettad
Copy link
Author

nettad commented Feb 18, 2014

Nice!

@holograph holograph modified the milestones: 0.4, 0.3 Mar 20, 2014
@holograph holograph modified the milestones: 0.5, 0.4 Jul 23, 2014
@holograph holograph changed the title Inline expressions in validator Support inline expressions in validators Jul 23, 2014
@holograph holograph modified the milestones: 0.7, 0.5 Jul 27, 2015
@holograph holograph modified the milestones: 1.0, 0.7 Aug 6, 2016
@holograph
Copy link
Contributor

The necessary mechanism for rewriting the code ended up being quite complex (equal to, or possibly rivalling, the complexity of the async/await code transformation). I wonder if there's enough interest in this feature to warrant the time?

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

No branches or pull requests

2 participants