mirror of
https://github.com/erg-lang/erg.git
synced 2025-08-03 18:29:00 +00:00
test: add inherit.er
This commit is contained in:
parent
8c2f5ec55f
commit
1dae378678
3 changed files with 22 additions and 2 deletions
|
@ -1271,7 +1271,7 @@ impl Context {
|
|||
let one = attr_name
|
||||
.as_ref()
|
||||
.map(|attr| {
|
||||
ctxs.into_iter()
|
||||
ctxs.iter()
|
||||
.flat_map(|ctx| {
|
||||
ctx.get_singular_ctxs_by_ident(attr, self)
|
||||
.ok()
|
||||
|
@ -1279,7 +1279,7 @@ impl Context {
|
|||
})
|
||||
.collect()
|
||||
})
|
||||
.unwrap_or(vec![]);
|
||||
.unwrap_or(ctxs);
|
||||
let two = obj
|
||||
.qual_name()
|
||||
.map(|name| {
|
||||
|
|
15
tests/should_ok/inherit.er
Normal file
15
tests/should_ok/inherit.er
Normal file
|
@ -0,0 +1,15 @@
|
|||
@Inheritable
|
||||
C = Class { .x = Int }
|
||||
C.
|
||||
const = 0
|
||||
C.
|
||||
new x: Int = C::__new__ { .x = x }
|
||||
|
||||
D = Inherit C
|
||||
D.
|
||||
@Override
|
||||
new x: Int = D::__new__ { .x = x }
|
||||
|
||||
d: D = D.new(1)
|
||||
print! d
|
||||
assert D.const == 0
|
|
@ -81,6 +81,11 @@ fn exec_import() -> Result<(), ()> {
|
|||
expect_success("examples/import.er")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_inherit() -> Result<(), ()> {
|
||||
expect_success("tests/should_ok/inherit.er")
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn exec_infer_class() -> Result<(), ()> {
|
||||
expect_success("tests/should_ok/infer_class.er")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue