Skip to content

Commit e73ac20

Browse files
committed
instantiation: Add unit tests for name resolution and typecheck
1 parent 1765c13 commit e73ac20

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
@@ -357,9 +357,11 @@ impl<'enclosing> NameResolveCtx<'enclosing> {
357357
.fold(HashMap::new(), |mut map, reqd| {
358358
let required_node = &fir[&reqd];
359359

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

365367
map.insert(reqd, scope);
@@ -704,4 +706,32 @@ mod tests {
704706

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

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)