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

Provide more descriptive validation message for inline maps with non stringy keys #7353

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ object SpelExpressionParseError {

case object MapWithExpressionKeysError extends UnsupportedOperationError {
override def message: String =
"Currently inline maps with not literal keys (e.g. expressions as keys) are not supported"
"Currently inline maps with not literal stringy keys (e.g. expressions as keys, numerals) are not supported"
}

case object ArrayConstructorError extends UnsupportedOperationError {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package pl.touk.nussknacker.engine.spel

import cats.data.Validated.Valid
import cats.data.ValidatedNel
import cats.data.Validated.{Invalid, Valid}
import cats.data.{NonEmptyList, ValidatedNel}
import org.scalatest.funsuite.AnyFunSuite
import org.scalatest.matchers.should.Matchers
import org.springframework.expression.common.TemplateParserContext
Expand All @@ -15,6 +15,7 @@ import pl.touk.nussknacker.engine.dict.{KeysDictTyper, SimpleDictRegistry}
import pl.touk.nussknacker.engine.expression.PositionRange
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.IllegalOperationError.DynamicPropertyAccessError
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.MissingObjectError.NoPropertyError
import pl.touk.nussknacker.engine.spel.SpelExpressionParseError.UnsupportedOperationError.MapWithExpressionKeysError
import pl.touk.nussknacker.engine.spel.Typer.TypingResultWithContext
import pl.touk.nussknacker.engine.spel.TyperSpecTestData.TestRecord._
import pl.touk.nussknacker.engine.util.Implicits.RichScalaMap
Expand All @@ -29,6 +30,12 @@ class TyperSpec extends AnyFunSuite with Matchers with ValidatedValuesDetailedMe
private val parser: standard.SpelExpressionParser =
new org.springframework.expression.spel.standard.SpelExpressionParser()

test("not allow maps with keys other than strings") {
typeExpression("{1L: 'foo'}") shouldBe Invalid(
NonEmptyList(MapWithExpressionKeysError, List())
)
}

test("simple expression") {
typeExpression("#x + 2", "x" -> 2) shouldBe Valid(
CollectedTypingResult(
Expand Down
Loading