Skip to content

Commit

Permalink
Prepare things before big refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri authored and lpil committed Jun 22, 2024
1 parent 084a9b9 commit f7dd48b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 59 deletions.
16 changes: 14 additions & 2 deletions compiler-core/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,13 @@ where
}
};
};

if tail.is_some() && !elements_end_with_comma {
// TODO)) Raise warning!
// Warning::DeprecatedListPrependSyntax {
// location: SrcSpan { start, end },
// })
}
}

let (_, end) = self.expect_one(&Token::RightSquare)?;
Expand Down Expand Up @@ -558,8 +565,6 @@ where

UntypedExpr::List {
location: SrcSpan { start, end },
// todo)) uses_deprecated_append_syntax: tail.is_some() && !elements_end_with_comma,
// TODO)) spread_location,
elements,
tail,
}
Expand Down Expand Up @@ -1163,6 +1168,13 @@ where
let mut dot_dot_location = None;
let tail = if let Some((start, Token::DotDot, end)) = self.tok0 {
dot_dot_location = Some((start, end));
if !elements_end_with_comma {
// TODO)) Raise warning
// Warning::DeprecatedListPatternSyntax {
// location: SrcSpan { start, end },
// }
}

self.advance();
let pat = self.parse_pattern()?;
if self.maybe_one(&Token::Comma).is_some() {
Expand Down
9 changes: 0 additions & 9 deletions compiler-core/src/type_/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -844,15 +844,6 @@ impl<'a, 'b> ExprTyper<'a, 'b> {
tail: Option<Box<UntypedExpr>>,
location: SrcSpan,
) -> Result<TypedExpr, Error> {
// TODO))
// if uses_deprecated_append_syntax {
// self.environment
// .warnings
// .emit(Warning::DeprecatedListPrependSyntax {
// location: spread_location.unwrap_or(location),
// })
// }

let typ = self.new_unbound_var();
// Type check each elements
let elements = elements
Expand Down
85 changes: 37 additions & 48 deletions compiler-core/src/type_/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,57 +321,46 @@ impl<'a, 'b> PatternTyper<'a, 'b> {
elements,
tail,
..
} => {
// TODO))
//if uses_deprecated_tail_pattern_syntax {
// self.environment
// .warnings
// .emit(Warning::DeprecatedListPatternSyntax {
// location: spread_location.unwrap_or(location),
// });
//}

match type_.get_app_args(
Publicity::Public,
PRELUDE_PACKAGE_NAME,
PRELUDE_MODULE_NAME,
"List",
1,
self.environment,
) {
Some(args) => {
let type_ = args
.first()
.expect("Failed to get type argument of List")
.clone();
let elements = elements
.into_iter()
.map(|element| self.unify(element, type_.clone()))
.try_collect()?;
let type_ = list(type_);

let tail = match tail {
Some(tail) => Some(Box::new(self.unify(*tail, type_.clone())?)),
None => None,
};

Ok(Pattern::List {
location,
elements,
tail,
type_,
})
}
} => match type_.get_app_args(
Publicity::Public,
PRELUDE_PACKAGE_NAME,
PRELUDE_MODULE_NAME,
"List",
1,
self.environment,
) {
Some(args) => {
let type_ = args
.first()
.expect("Failed to get type argument of List")
.clone();
let elements = elements
.into_iter()
.map(|element| self.unify(element, type_.clone()))
.try_collect()?;
let type_ = list(type_);

None => Err(Error::CouldNotUnify {
given: list(self.environment.new_unbound_var()),
expected: type_.clone(),
situation: None,
let tail = match tail {
Some(tail) => Some(Box::new(self.unify(*tail, type_.clone())?)),
None => None,
};

Ok(Pattern::List {
location,
rigid_type_names: hashmap![],
}),
elements,
tail,
type_,
})
}
}

None => Err(Error::CouldNotUnify {
given: list(self.environment.new_unbound_var()),
expected: type_.clone(),
situation: None,
location,
rigid_type_names: hashmap![],
}),
},

Pattern::Tuple { elems, location } => match collapse_links(type_.clone()).deref() {
Type::Tuple { elems: type_elems } => {
Expand Down

0 comments on commit f7dd48b

Please sign in to comment.