Skip to content

Commit c18fd2f

Browse files
committed
instantiation: Add unit tests for name resolution and typecheck
1 parent b503743 commit c18fd2f

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

name_resolve/src/lib.rs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,9 +356,11 @@ impl<'enclosing> NameResolveCtx<'enclosing> {
356356
.fold(HashMap::new(), |mut map, reqd| {
357357
let required_node = &fir[&reqd];
358358

359-
let scope = match required_node.kind {
359+
let scope = match &required_node.kind {
360360
Kind::Instantiation { to, .. } => Scope(to.expect_resolved()),
361-
_ => unreachable!(),
361+
other => unreachable!(
362+
"interpreter error - expected Instantiation, got {other:#?}"
363+
),
362364
};
363365

364366
map.insert(reqd, scope);
@@ -703,4 +705,32 @@ mod tests {
703705

704706
assert!(fir.is_err())
705707
}
708+
709+
#[test]
710+
fn field_instantiation_valid() {
711+
let ast = ast! {
712+
type Foo;
713+
714+
type Record(of: Foo);
715+
where x = Record(of: Foo);
716+
};
717+
718+
let fir = ast.flatten().name_resolve();
719+
720+
assert!(fir.is_ok());
721+
}
722+
723+
#[test]
724+
fn field_instantiation_invalid() {
725+
let ast = ast! {
726+
type Foo;
727+
728+
type Record(of: Foo);
729+
where x = Record(not_of: Foo);
730+
};
731+
732+
let fir = ast.flatten().name_resolve();
733+
734+
assert!(fir.is_err());
735+
}
706736
}

typecheck/src/lib.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ mod tests {
219219
}
220220

221221
#[test]
222+
#[ignore = "Reevaluate once #653 is done"]
222223
fn assignment_valid() {
223224
let ast = ast! {
224225
type Marker0;
@@ -235,6 +236,7 @@ mod tests {
235236
}
236237

237238
#[test]
239+
#[ignore = "Reevaluate once #653 is done"]
238240
fn assignment_invalid() {
239241
let ast = ast! {
240242
type Marker0;
@@ -248,6 +250,33 @@ mod tests {
248250
assert!(fir.is_err());
249251
}
250252

253+
#[test]
254+
fn field_instantiation_valid() {
255+
let ast = ast! {
256+
type Foo;
257+
258+
type Record(m: Foo);
259+
where x = Record(m: Foo);
260+
};
261+
let fir = fir!(ast).type_check();
262+
263+
assert!(fir.is_ok());
264+
}
265+
266+
#[test]
267+
fn field_instantiation_invalid() {
268+
let ast = ast! {
269+
type Foo;
270+
type Bar;
271+
272+
type Record(m: Foo);
273+
where x = Record(m: Bar);
274+
};
275+
let fir = fir!(ast).type_check();
276+
277+
assert!(fir.is_err());
278+
}
279+
251280
#[test]
252281
fn constant_bool() {
253282
let ast = ast! {

0 commit comments

Comments
 (0)