Skip to content
This repository was archived by the owner on Apr 14, 2020. It is now read-only.

Commit 64a303e

Browse files
committed
Fixed the last failing test, caused by a underflow in tuple_name
1 parent b1db5b7 commit 64a303e

File tree

3 files changed

+22
-22
lines changed

3 files changed

+22
-22
lines changed

lambda_lift.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ fn free_variables(&mut self, variables: &mut HashMap<Name, isize>, free_vars: &m
3939
Identifier(ref mut i) => {
4040
//If the identifier is a local, add it to the free variables
4141
if variables.get(&i.name).map(|x| *x > 0).unwrap_or(false) {
42-
match variables.entry(i.name.clone()) {
43-
Entry::Vacant(entry) => { entry.insert(1); }
44-
Entry::Occupied(mut entry) => *entry.get_mut() += 1
45-
}
42+
free_vars.insert(i.name.clone(), i.clone());
4643
}
4744
}
4845
Apply(ref mut func, ref mut arg) => {

parser.rs

+19-17
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,8 @@ fn type_declaration(&mut self) -> TypeDeclaration {
743743
}
744744

745745
fn constrained_type(&mut self) -> (Vec<Constraint>, Type) {
746-
let mut maybeConstraints = if self.lexer.next().token == LPARENS {
746+
debug!("Parse constrained type");
747+
let mut maybe_constraints = if self.lexer.next().token == LPARENS {
747748
if self.lexer.peek().token == RPARENS {
748749
self.lexer.next();
749750
vec![]
@@ -758,27 +759,28 @@ fn constrained_type(&mut self) -> (Vec<Constraint>, Type) {
758759
self.lexer.backtrack();
759760
vec![self.parse_type()]
760761
};
761-
let maybeContextArrow = self.lexer.next().token;
762+
debug!("{:?}", maybe_constraints);
762763
//If there is => arrow we proceed to parse the type
763-
let typ = if maybeContextArrow == CONTEXTARROW {
764-
self.parse_type()
765-
}
766-
else if maybeContextArrow == ARROW {
767-
self.lexer.backtrack();
768-
let mut args = Vec::new();
769-
swap(&mut args, &mut maybeConstraints);
770-
self.parse_return_type(make_tuple_type(args))
771-
}
772-
else {//If no => was found, translate the constraint list into a type
773-
self.lexer.backtrack();
774-
let mut args = Vec::new();
775-
swap(&mut args, &mut maybeConstraints);
776-
make_tuple_type(args)
764+
let typ = match self.lexer.next().token {
765+
CONTEXTARROW => self.parse_type(),
766+
ARROW => {
767+
self.lexer.backtrack();
768+
let mut args = Vec::new();
769+
swap(&mut args, &mut maybe_constraints);
770+
self.parse_return_type(make_tuple_type(args))
771+
}
772+
_ => {//If no => was found, translate the constraint list into a type
773+
self.lexer.backtrack();
774+
let mut args = Vec::new();
775+
swap(&mut args, &mut maybe_constraints);
776+
make_tuple_type(args)
777+
}
777778
};
778-
(make_constraints(maybeConstraints), typ)
779+
(make_constraints(maybe_constraints), typ)
779780
}
780781

781782
fn constructor_type(&mut self, arity : &mut isize, dataDef: &DataDefinition) -> Type {
783+
debug!("Parse constructor type");
782784
let token = self.lexer.next().token;
783785
if token == NAME {
784786
*arity += 1;

types.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,9 @@ impl <S: ::std::hash::Hasher + ::std::hash::Writer> ::std::hash::Hash<S> for Typ
142142

143143
///Constructs a string which holds the name of an n-tuple
144144
pub fn tuple_name(n: usize) -> String {
145+
let commas = if n == 0 { 0 } else { n - 1 };
145146
Some('(').into_iter()
146-
.chain(iter::repeat(',').take(n - 1))
147+
.chain(iter::repeat(',').take(commas))
147148
.chain(Some(')').into_iter())
148149
.collect()
149150
}

0 commit comments

Comments
 (0)