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

More nested-path functionalities #493

Merged
merged 20 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
561124b
Start using stubbed Paths for recursion rules (without testing yet)
MateuszKubuszok Apr 5, 2024
ae63c21
Rewrite a few usages of tpe.Underlying into Tpe, when import tpe.Unde…
MateuszKubuszok Apr 5, 2024
8a94eaa
Prototype of a nested-paths for subtypes and collections (internally,…
MateuszKubuszok Apr 5, 2024
9b9b749
Create extension methods for onSubtype/on.../eachItem/each... in DSL
MateuszKubuszok Apr 7, 2024
2159ce8
Scala 3 DSL parsing implementation, the first test for new nested con…
MateuszKubuszok Apr 8, 2024
6d06130
Fix more issues on Scala 3
MateuszKubuszok Apr 8, 2024
0828c0f
Modify implicits and DSL on Scala 2 to make DSL extensions for nested…
MateuszKubuszok Apr 8, 2024
68ffa2e
Change everyItem, everyMapKey and everyMapValue implementation in Sca…
MateuszKubuszok Apr 9, 2024
19cb771
Add implicitNotFound to IsOption, IsEither, IsCollection, IsMap type …
MateuszKubuszok Apr 9, 2024
68e6cb1
Revert some unnecessary changes (in benchmarks, unneeded renames, Fro…
MateuszKubuszok Apr 10, 2024
78c4e6e
Restore old behavior for computing error paths for converting pair co…
MateuszKubuszok Apr 10, 2024
5b2c5e5
Limit the number of pointless asInstanceOf in generated code
MateuszKubuszok Apr 10, 2024
bc8c212
More tests in Total Product spec
MateuszKubuszok Apr 10, 2024
d53cc6e
Merge widenExpr and upcastExpr into upcastToExprOf since they are bas…
MateuszKubuszok Apr 10, 2024
7330cc8
Happy-path nested-paths tests for Products
MateuszKubuszok Apr 10, 2024
820357f
Check nested-paths DSL in Product specs
MateuszKubuszok Apr 10, 2024
9542222
Refine nested-path DSL error messages
MateuszKubuszok Apr 10, 2024
2878c21
Test nested-paths DSL with std lib types, document nested-paths DSL
MateuszKubuszok Apr 10, 2024
99551ff
Initial documentation for nested paths in Chimney DSL
MateuszKubuszok Apr 10, 2024
d1a0d40
Document evidence types and suppress their coverage
MateuszKubuszok Apr 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refine nested-path DSL error messages
  • Loading branch information
MateuszKubuszok committed Apr 10, 2024
commit 95422229efaf324aa508a3ae309ebe13ccfac331
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

private trait ExistentialType {
type Underlying
val Underlying: c.WeakTypeTag[Underlying]

Check warning on line 24 in chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L24

Added line #L24 was not covered by tests
}
private object ExistentialType {

Expand Down Expand Up @@ -60,7 +60,7 @@
val Underlying: WeakTypeTag[runtime.Path.Root] = weakTypeTag[runtime.Path.Root]
})
// matches `_ => something unrelated` - not allowed
case _: Ident => Left(ignoringInputNotAllowed(t))
case i: Ident => Left(ignoringInputNotAllowed(i, t))
// matches `...()`
case Apply(select @ Select(_, _), Nil) => unpackSelects(select)
// matches `.matching[Subtype]`
Expand Down Expand Up @@ -172,22 +172,24 @@
applyTypes(init.Underlying)
}
// matches `someFunctionName` - not allowed
case Apply(_, _) => Left(arbitraryFunctionNotAllowed(t))
case _ => Left(invalidSelectorErrorMessage(t))
case f @ Apply(_, _) => Left(arbitraryFunctionNotAllowed(f, t))
case _ => Left(invalidSelectorErrorMessage(t))
}

unpackSelects(selects)
case _ => Left(invalidSelectorErrorMessage(t))
}

private def invalidSelectorErrorMessage(selectorTree: Tree): String =
s"Invalid selector expression: $selectorTree"
import Console.*

private def arbitraryFunctionNotAllowed(selectorTree: Tree): String =
s"The path expression has to be a single chain of calls on the original input, operation other than value extraction: $selectorTree\n${showRaw(selectorTree)}"
private def invalidSelectorErrorMessage(t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got: $MAGENTA$t$RESET"

Check warning on line 186 in chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L186

Added line #L186 was not covered by tests

private def ignoringInputNotAllowed(selectorTree: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got external identifier: $selectorTree"
private def arbitraryFunctionNotAllowed(f: Tree, t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got operation other than value extraction: $MAGENTA$f$RESET in $MAGENTA$t$RESET"

Check warning on line 190 in chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-2/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L190

Added line #L190 was not covered by tests
private def ignoringInputNotAllowed(i: Tree, t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got external identifier: $MAGENTA$i$RESET in: $MAGENTA$t$RESET"
}

private trait ExistentialCtor {
Expand Down Expand Up @@ -258,8 +260,10 @@
)
}

import Console.*

private def invalidConstructor(t: Tree): String =
s"Expected function, instead got: ${Console.MAGENTA}$t${Console.RESET}: ${Console.MAGENTA}${t.tpe}${Console.RESET}"
s"Expected function, instead got: $MAGENTA$t$RESET: $MAGENTA${t.tpe}$RESET"
}

// If we try to do:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
private object IsOptionOf {
def unapply(term: Term): Option[(ExistentialType, ExistentialType, ExistentialType)] = term.tpe.asType match {
case '[runtime.IsOption.Of[o, sv, s]] => Some((ExistentialType[o], ExistentialType[sv], ExistentialType[s]))
case _ => None

Check warning on line 24 in chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L24

Added line #L24 was not covered by tests
}
}

Expand All @@ -32,7 +32,7 @@
term.tpe.asType match {
case '[runtime.IsEither.Of[e, lv, rv, l, r]] =>
Some((ExistentialType[e], ExistentialType[lv], ExistentialType[rv], ExistentialType[l], ExistentialType[r]))
case _ => None

Check warning on line 35 in chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L35

Added line #L35 was not covered by tests
}
}

Expand All @@ -40,7 +40,7 @@
def unapply(term: Term): Option[(ExistentialType, ExistentialType)] =
term.tpe.asType match {
case '[runtime.IsCollection.Of[c, a]] => Some((ExistentialType[c], ExistentialType[a]))
case _ => None

Check warning on line 43 in chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L43

Added line #L43 was not covered by tests
}
}

Expand All @@ -48,7 +48,7 @@
def unapply(term: Term): Option[(ExistentialType, ExistentialType, ExistentialType)] =
term.tpe.asType match {
case '[runtime.IsMap.Of[m, k, v]] => Some((ExistentialType[m], ExistentialType[k], ExistentialType[v]))
case _ => None

Check warning on line 51 in chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L51

Added line #L51 was not covered by tests
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@
val Underlying: Type[runtime.Path.Root] = Type.of[runtime.Path.Root]
})
// matches `_ => something unrelated` - not allowed
case _: Ident => Left(ignoringInputNotAllowed(t))
case i: Ident => Left(ignoringInputNotAllowed(i, t))
// matches `.fieldName` AND `.fieldName()`
case SelectLike(t2, fieldName) =>
unpackSelects(t2).map { init =>
Expand Down Expand Up @@ -182,23 +182,26 @@
}
}
// matches `someFunctionName` - not allowed
case Apply(_, _) => Left(arbitraryFunctionNotAllowed(t))
case _ => Left(invalidSelectorErrorMessage(t))
case f @ Apply(_, _) => Left(arbitraryFunctionNotAllowed(f, t))
case _ => Left(invalidSelectorErrorMessage(t))

Check warning on line 186 in chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L186

Added line #L186 was not covered by tests
}
unpackSelects(selects)
case Inlined(_, _, block) => parse(block)
case _ => Left(invalidSelectorErrorMessage(t))
}

private def invalidSelectorErrorMessage(t: Tree): String =
s"Invalid selector expression: ${t.show(using Printer.TreeAnsiCode)}"
s"The path expression has to be a single chain of calls on the original input, got: ${t.show(using Printer.TreeAnsiCode)}"

Check warning on line 194 in chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala

View check run for this annotation

Codecov / codecov/patch

chimney/src/main/scala-3/io/scalaland/chimney/internal/compiletime/dsl/utils/DslMacroUtils.scala#L194

Added line #L194 was not covered by tests

private def arbitraryFunctionNotAllowed(t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, operation other than value extraction: ${t
private def arbitraryFunctionNotAllowed(f: Tree, t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got operation other than value extraction: ${f
.show(using Printer.TreeAnsiCode)} in: ${t
.show(using Printer.TreeAnsiCode)}"

private def ignoringInputNotAllowed(t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got external identifier: ${t.show(using Printer.TreeAnsiCode)}"
private def ignoringInputNotAllowed(i: Tree, t: Tree): String =
s"The path expression has to be a single chain of calls on the original input, got external identifier: ${i.show(
using Printer.TreeAnsiCode
)} in: ${t.show(using Printer.TreeAnsiCode)}"
}

private trait ExistentialCtor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PartialTransformerProductSpec extends ChimneySpec {
import products.{Foo, Bar, HaveY}

compileErrorsFixed("""Bar(3, (3.14, 3.14)).intoPartial[Foo].withFieldConst(_.y + "abc", "pi").transform""").check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down Expand Up @@ -242,7 +242,7 @@ class PartialTransformerProductSpec extends ChimneySpec {
.transform
"""
).check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down Expand Up @@ -420,7 +420,7 @@ class PartialTransformerProductSpec extends ChimneySpec {
Bar(3, (3.14, 3.14)).intoPartial[Foo].withFieldComputed(_.y + "abc", _.toString).transform
"""
).check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down Expand Up @@ -601,7 +601,7 @@ class PartialTransformerProductSpec extends ChimneySpec {
Bar(3, (3.14, 3.14)).intoPartial[Foo].withFieldComputedPartial(_.y + "abc", _ => ???).transform
"""
).check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down Expand Up @@ -817,7 +817,7 @@ class PartialTransformerProductSpec extends ChimneySpec {
User(1, "Kuba", Some(28)).intoPartial[UserPL].withFieldRenamed(_.age + "ABC", _.toString).transform
"""
).check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class TotalTransformerProductSpec extends ChimneySpec {
import products.{Foo, Bar, HaveY}

compileErrorsFixed("""Bar(3, (3.14, 3.14)).into[Foo].withFieldConst(_.y + "abc", "pi").transform""").check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down Expand Up @@ -148,7 +148,7 @@ class TotalTransformerProductSpec extends ChimneySpec {

compileErrorsFixed("""Bar(3, (3.14, 3.14)).into[Foo].withFieldComputed(_.y + "abc", _.toString).transform""")
.check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down Expand Up @@ -273,7 +273,7 @@ class TotalTransformerProductSpec extends ChimneySpec {
compileErrorsFixed(
"""User(1, "Kuba", Some(28)).into[UserPL].withFieldRenamed(_.age + "ABC", _.toString).transform"""
).check(
"The path expression has to be a single chain of calls on the original input, operation other than value extraction:"
"The path expression has to be a single chain of calls on the original input, got operation other than value extraction:"
)

compileErrorsFixed(
Expand Down
Loading