Fixes #881.
This commit is contained in:
parent
4f8e900aac
commit
bee2b712de
|
@ -1835,6 +1835,30 @@ fn forbid_expect_into_opaque_type_from_data() {
|
|||
))
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allow_expect_into_type_from_data() {
|
||||
let source_code = r#"
|
||||
fn bar(n: Data) {
|
||||
expect a: Option<Int> = n
|
||||
a
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(check(parse(source_code)).is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn allow_expect_into_type_from_data_2() {
|
||||
let source_code = r#"
|
||||
fn bar(n: Data) {
|
||||
expect Some(a): Option<Int> = n
|
||||
a
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(check(parse(source_code)).is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forbid_expect_into_opaque_type_constructor_without_typecasting_in_module() {
|
||||
let source_code = r#"
|
||||
|
@ -1985,6 +2009,19 @@ fn allow_expect_on_var_patterns_that_are_opaque() {
|
|||
assert!(check(parse(source_code)).is_ok())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_down_cast_to_data_always() {
|
||||
let source_code = r#"
|
||||
pub opaque type Foo { x: Int }
|
||||
pub fn bar(a: Foo) {
|
||||
let b: Data = a
|
||||
b
|
||||
}
|
||||
"#;
|
||||
|
||||
assert!(check(parse(source_code)).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn correct_span_for_backpassing_args() {
|
||||
let source_code = r#"
|
||||
|
|
|
@ -1415,12 +1415,12 @@ impl<'a> Environment<'a> {
|
|||
&& !(t1.is_function() || t2.is_function())
|
||||
&& !(t1.is_generic() || t2.is_generic())
|
||||
&& !(t1.is_string() || t2.is_string())
|
||||
&& !(t1.contains_opaque() || t2.contains_opaque())
|
||||
&& !t1.contains_opaque()
|
||||
{
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if allow_cast && (t1.contains_opaque() || t2.contains_opaque()) {
|
||||
if allow_cast && t1.contains_opaque() {
|
||||
return Err(Error::ExpectOnOpaqueType { location });
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue