Skip to content

Commit

Permalink
feat: Merge the types in conditionl expressions
Browse files Browse the repository at this point in the history
Instead of assuming they share the `consequent` type.
  • Loading branch information
Markus Westerlind committed Feb 15, 2022
1 parent ebe8a82 commit 74fd307
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
5 changes: 5 additions & 0 deletions libflux/flux-core/src/semantic/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,8 +1031,13 @@ impl<'a> Converter<'a> {
test,
consequent,
alternate,
<<<<<<< HEAD
typ: MonoType::Error,
}
=======
typ: MonoType::Var(self.sub.fresh()),
})
>>>>>>> 48a598b5 (feat: Merge the types in conditionl expressions)
}

fn convert_object_expression(&mut self, expr: &ast::ObjectExpr) -> ObjectExpr {
Expand Down
6 changes: 6 additions & 0 deletions libflux/flux-core/src/semantic/formatter/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,14 @@ fn format_block_statement() {
expect![[r##"
package main
(r) => {
<<<<<<< HEAD
v = (if r:#A <:bool 0 then -r:#A:#A else r:#A):#A
return v:#A *:#A v:#A
}:(r:#A) => #A"##]],
=======
v = (if r:t10 <:bool 0 then -r:t10:t10 else r:t10):t10
return v:t10 *:t10 v:t10
}:(r:t10) => t10"#]],
>>>>>>> 48a598b5 (feat: Merge the types in conditionl expressions)
)
}
1 change: 0 additions & 1 deletion libflux/flux-core/src/semantic/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ pub fn instantiate(
sub: &mut Substitution,
loc: SourceLocation,
) -> (MonoType, Constraints) {
eprintln!("Instantiate {}", poly);
// Substitute fresh type variables for all quantified variables
let sub: SubstitutionMap = poly
.vars
Expand Down
9 changes: 6 additions & 3 deletions libflux/flux-core/src/semantic/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -893,9 +893,12 @@ impl MonoType {

(MonoType::Builtin(exp), MonoType::Builtin(act)) => exp.unify(*act, unifier),

(MonoType::Label(_), MonoType::Label(_)) => (),
(MonoType::Builtin(BuiltinType::String), MonoType::Label(_))
| (MonoType::Label(_), MonoType::Builtin(BuiltinType::String)) => (),
(MonoType::Label(l), MonoType::Label(r)) if l == r => {}
(MonoType::Label(_), MonoType::Label(_))
| (MonoType::Builtin(BuiltinType::String), MonoType::Label(_))
| (MonoType::Label(_), MonoType::Builtin(BuiltinType::String)) => {
return MonoType::STRING
}

(MonoType::Var(tv), MonoType::Var(tv2)) => {
match (unifier.sub.try_apply(*tv), unifier.sub.try_apply(*tv2)) {
Expand Down

0 comments on commit 74fd307

Please sign in to comment.