Skip to content

Commit

Permalink
Merge pull request #98 from databricks/edgar/fix-match-error-when-plu…
Browse files Browse the repository at this point in the history
…s-is-true-in-object-declaration

Fix compiler crash when '+' signal is true in a field declaration inside a list comprehension
  • Loading branch information
edsilfer authored Nov 6, 2020
2 parents 5ccdb4c + 8850052 commit 1e87561
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ output/
.DS_STORE
.idea_modules
.idea
.metals
.vscode
out/
2 changes: 1 addition & 1 deletion sjsonnet/src/sjsonnet/Parser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ object Parser{
val preLocals = exprs
.takeWhile(_.isInstanceOf[Expr.Member.BindStmt])
.map(_.asInstanceOf[Expr.Member.BindStmt])
val Expr.Member.Field(offset, Expr.FieldName.Dyn(lhs), false, None, Visibility.Normal, rhs) =
val Expr.Member.Field(offset, Expr.FieldName.Dyn(lhs), _, None, Visibility.Normal, rhs) =
exprs(preLocals.length)
val postLocals = exprs.drop(preLocals.length+1).takeWhile(_.isInstanceOf[Expr.Member.BindStmt])
.map(_.asInstanceOf[Expr.Member.BindStmt])
Expand Down
7 changes: 7 additions & 0 deletions sjsonnet/test/src/sjsonnet/EvaluatorTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -321,5 +321,12 @@ object EvaluatorTests extends TestSuite{
"""sjsonnet.Error: Adjacent object literals not allowed in strict mode - Use '+' to concatenate objects
|at .(:1:31)""".stripMargin
}
test("objectDeclaration") {
eval("{ ['foo']: x for x in []}", false) ==> ujson.Obj()
eval("{ ['foo']: x for x in [1]}", false) ==> ujson.Obj("foo" -> 1)

eval("{ ['foo']+: x for x in []}", false) ==> ujson.Obj()
eval("{ ['foo']+: x for x in [1]}", false) ==> ujson.Obj("foo" -> 1)
}
}
}

0 comments on commit 1e87561

Please sign in to comment.