Skip to content

Commit

Permalink
fix: Remove redundant restriction at compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
Iltotore committed Jun 2, 2023
1 parent b401ea6 commit 0f42931
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 22 deletions.
1 change: 0 additions & 1 deletion main/src/io/github/iltotore/iron/conversion.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import scala.language.implicitConversions
* @note This method ensures that the value satisfies the constraint. If it doesn't or isn't evaluable at compile-time, the compilation is aborted.
*/
implicit inline def autoRefine[A, C](inline value: A)(using inline constraint: Constraint[A, C]): A :| C =
inline if !macros.isConstant(value) then macros.nonConstantError(value)
macros.assertCondition(value, constraint.test(value), constraint.message)
IronType(value)

Expand Down
21 changes: 0 additions & 21 deletions main/src/io/github/iltotore/iron/macros/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,6 @@ private def assertConditionImpl[A: Type](input: Expr[A], cond: Expr[Boolean], me
|${CYAN}Message$RESET: $messageValue""".stripMargin)
'{}

/**
* Throw compile-time error indicating that the given value is not constant.
*
* @param value the non-constant value, used in the error message.
* @tparam A the type of `value`.
*/
inline def nonConstantError[A](inline value: A): Nothing = ${ nonConstantErrorImpl('value) }

private def nonConstantErrorImpl[A](expr: Expr[A])(using Quotes): Nothing =

import quotes.reflect.*

compileTimeError(
s"""Cannot refine non full inlined input at compile-time.
|To test a constraint at runtime, use the `refine` extension method.
|
|Note: Due to a Scala limitation, already-refined types cannot be tested at compile-time (unless proven by an `Implication`).
|
|${CYAN}Inlined input$RESET: ${expr.asTerm.show}""".stripMargin
)

/**
* Checks if the given value is constant (aka evaluable at compile time).
*
Expand Down

0 comments on commit 0f42931

Please sign in to comment.