-
Notifications
You must be signed in to change notification settings - Fork 9
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
Unions don't seem to be typechecked correctly #185
Comments
What you're describing is 100% intended behavior, since the conversion operations provided by Dhall for Java do not type-check their inputs. For example scala> import org.dhallj.syntax._
import org.dhallj.syntax._
scala> val Right(expr) = "[1, True]".parseExpr
val expr: org.dhallj.core.Expr = [1, True]
scala> expr.typeCheck
val res1: Either[org.dhallj.core.typechecking.TypeCheckFailure,org.dhallj.core.Expr] = Left(org.dhallj.core.typechecking.TypeCheckFailure: List elements should all have the same type) You can still do many things with it, though: scala> expr.normalize
val res1: org.dhallj.core.Expr = [1, True]
scala> expr.diff(expr)
val res2: Option[(Option[org.dhallj.core.Expr], Option[org.dhallj.core.Expr])] = None
scala> import org.dhallj.circe.Converter
import org.dhallj.circe.Converter
scala> Converter(expr)
val res3: Option[io.circe.Json] =
Some([
1,
true
]) This approach isn't specific to Dhall for Java. If you pipe
There's no indication that the It's even possible to construct Dhall expressions that are ill-typed but become well-typed after normalization (e.g. The idea in general is that components like scala> val bad = "let Package = < GitHub : { repository : Text, revision : Text } > in [ Package.GitHub { repository = {} } ]"
val bad: String = let Package = < GitHub : { repository : Text, revision : Text } > in [ Package.GitHub { repository = {} } ]
scala> val Right(badExpr) = bad.parseExpr
val badExpr: org.dhallj.core.Expr = let Package = <GitHub : {repository : Text, revision : Text}> in [(Package.GitHub) {repository = {}}]
scala> badExpr.typeCheck
val res4: Either[org.dhallj.core.typechecking.TypeCheckFailure,org.dhallj.core.Expr] = Left(org.dhallj.core.typechecking.TypeCheckFailure: Wrong type of function argument) It's possible this could be better documented, either here or in the general Dhall documentation, but the behavior itself won't change, so I'm closing this issue. |
Thank you for the detailed explanation, my Dhall knowledge is far from perfect. Definitely doesn't look like bug in dhallj then 👍 |
In the following Dhall expression:
We should get a type error because of
repository
not being a Text, andrevision
being missing. Dhall's editor on the website says:Instead, if I try to normalize this expression and encode it as JSON using the circe encoder:
The last line prints:
Some([ { } ])
The result of normalization prints as
[(<GitHub : {repository : Text, revision : Text}>.GitHub) {repository = {}}]
.If I skip
repository = {}
completely, I getSome([\n])
.If
Package
is just a record and not a union, it works as expected.The text was updated successfully, but these errors were encountered: