diff options
author | Nadrieril | 2019-05-02 17:37:29 +0200 |
---|---|---|
committer | Nadrieril | 2019-05-02 17:37:29 +0200 |
commit | 26251618301156dddb89b159255955beb41996af (patch) | |
tree | f5416c92dee13d942c9a014da329da81a5b59a55 /dhall/src | |
parent | c31600fa689c97f3a19bc6a152cb8d13eb64f5d1 (diff) |
Typecheck text interpolation
Diffstat (limited to '')
-rw-r--r-- | dhall/src/typecheck.rs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/dhall/src/typecheck.rs b/dhall/src/typecheck.rs index 96c8546..13ffb48 100644 --- a/dhall/src/typecheck.rs +++ b/dhall/src/typecheck.rs @@ -967,8 +967,20 @@ fn type_last_layer( NaturalLit(_) => Ok(RetType(builtin_to_type(Natural)?)), IntegerLit(_) => Ok(RetType(builtin_to_type(Integer)?)), DoubleLit(_) => Ok(RetType(builtin_to_type(Double)?)), - // TODO: check type of interpolations - TextLit(_) => Ok(RetType(builtin_to_type(Text)?)), + TextLit(interpolated) => { + let text_type = builtin_to_type(Text)?; + for contents in interpolated.iter() { + use InterpolatedTextContents::Expr; + if let Expr(x) = contents { + ensure_equal!( + x.get_type()?, + &text_type, + mkerr(InvalidTextInterpolation(x)), + ); + } + } + Ok(RetType(text_type)) + } BinOp(o @ ListAppend, l, r) => { match l.get_type()?.internal_whnf() { Some(Value::AppliedBuiltin(List, _)) => {} @@ -1041,6 +1053,7 @@ pub(crate) enum TypeMessage<'a> { MissingUnionField(Label, Normalized<'a>), BinOpTypeMismatch(BinOp, Typed<'a>), NoDependentTypes(Normalized<'a>, Normalized<'a>), + InvalidTextInterpolation(Typed<'a>), Sort, Unimplemented, } @@ -1359,7 +1372,7 @@ mod spec_tests { tc_failure!(tc_failure_unit_RightBiasedRecordMergeRhsNotRecord, "unit/RightBiasedRecordMergeRhsNotRecord"); tc_failure!(tc_failure_unit_SomeNotType, "unit/SomeNotType"); tc_failure!(tc_failure_unit_Sort, "unit/Sort"); - // tc_failure!(tc_failure_unit_TextLiteralInterpolateNotText, "unit/TextLiteralInterpolateNotText"); + tc_failure!(tc_failure_unit_TextLiteralInterpolateNotText, "unit/TextLiteralInterpolateNotText"); tc_failure!(tc_failure_unit_TypeAnnotationWrong, "unit/TypeAnnotationWrong"); tc_failure!(tc_failure_unit_UnionConstructorFieldNotPresent, "unit/UnionConstructorFieldNotPresent"); tc_failure!(tc_failure_unit_UnionTypeMixedKinds, "unit/UnionTypeMixedKinds"); |