Skip to content

Commit

Permalink
Merge #558
Browse files Browse the repository at this point in the history
558: fix(repl): Don't panic on solo array literals r=Marwes a=Marwes

As the repl invokes the typechecker without an expected type any array
in the tail expression would not get a type assigned to them.

Fixes #555

Co-authored-by: Markus Westerlind <marwes91@gmail.com>
  • Loading branch information
bors[bot] and Marwes committed Jun 27, 2018
2 parents 0015f0b + 1ceed88 commit 6ca24a3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ before_deploy:
- >
if [[ $CURRENT_TAG != "" ]]; then
export GIT_HASH=$(git rev-parse HEAD)
travis_wait sh scripts/before_deploy.sh
sh scripts/before_deploy.sh
fi
deploy:
- provider: pages
Expand Down
2 changes: 1 addition & 1 deletion check/src/typecheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -916,8 +916,8 @@ impl<'a> Typecheck<'a> {
Expr::Array(ref mut array) => {
let mut expected_element_type = self.subs.new_var();

array.typ = self.type_cache.array(expected_element_type.clone());
if let Some(expected_type) = expected_type.take() {
array.typ = self.type_cache.array(expected_element_type.clone());
self.unify_span(expr.span, &expected_type, array.typ.clone());
}

Expand Down
13 changes: 13 additions & 0 deletions check/tests/pass.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,3 +919,16 @@ Test ""

assert!(result.is_ok(), "{}", result.unwrap_err());
}

#[test]
fn array_expr_gets_type_assigned_without_expected_type_issue_555() {
let _ = env_logger::try_init();

let text = r#"
[1]
"#;
let (expr, result) = support::typecheck_expr(text);

assert!(result.is_ok(), "{}", result.unwrap_err());
assert_eq!(expr.env_type_of(&MockEnv::new()).to_string(), "Array Int");
}

0 comments on commit 6ca24a3

Please sign in to comment.