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

Fixes refined types applies: #78

Merged
merged 4 commits into from
Oct 5, 2023
Merged

Conversation

dagmendez
Copy link
Collaborator

The apply methods of the refined types were broken since the bodies could not be inlined during "execution" time (in the console).

  • 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)

- 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.")
Copy link
Collaborator Author

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.")
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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+$"]]
Copy link
Collaborator Author

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."
Copy link
Collaborator Author

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.

@dagmendez dagmendez self-assigned this Oct 3, 2023
@dagmendez dagmendez merged commit fa430ff into main Oct 5, 2023
1 check passed
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.

1 participant