-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fixes refined types applies: #78
Conversation
- Removes the requireConstant method in the body of the applies since the body is also inlined. - inline match for enums - constValue[T] for refined primitives (String)
inline if int < 0 | ||
then error("Int must be positive.") | ||
then error(codeOf(int) + " is negative. Int must be positive.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injects the rejected value in the error message.
else nonEmptyString | ||
inline if constValue[Matches[nonEmptyString.type, "^\\S+$"]] | ||
then nonEmptyString | ||
else error(codeOf(nonEmptyString) + " is invalid. Empty String is not allowed here.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injects the rejected value in the error message.
@@ -154,10 +163,9 @@ object refinedTypes: | |||
* More info at [[https://docs.scala-lang.org/scala3/reference/metaprogramming/inline.html]] | |||
*/ | |||
inline def apply(nonEmptyString: String): NonEmptyString = | |||
requireConst(nonEmptyString) | |||
inline if nonEmptyString.isBlank |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
methods of the class java.String can not be inlined during compilation time.
inline if nonEmptyString.isBlank | ||
then error("Empty String is not allowed here.") | ||
else nonEmptyString | ||
inline if constValue[Matches[nonEmptyString.type, "^\\S+$"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It evaluates at compile time if the string contains any character different than empty (blank, spaces, hidden characters...)
case "zstd" => zstd | ||
case _: String => | ||
error: | ||
codeOf(kafkaCompressionType) + " is invalid.\nValid values are none, gzip, snappy, lz4 and zstd." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Injects the rejected value in the error message.
- Improves the logic for Inline apply for PositiveInt
The apply methods of the refined types were broken since the bodies could not be inlined during "execution" time (in the console).