-
Notifications
You must be signed in to change notification settings - Fork 222
Open
Labels
dslxDSLX (domain specific language) implementation / front-endDSLX (domain specific language) implementation / front-end
Description
Describe the bug
pub struct SomeType<FIRST: u32, SECOND: u32> { data: uN[FIRST] }
pub fn dostuff<FIRST: u32, SECOND: u32, COMPUTED: u32 = {SECOND}>
(a: SomeType<FIRST, SECOND>) -> SomeType<FIRST, SECOND> {
a
}
#[test]
fn test_dostuff() {
let a = SomeType<u32:4, u32:4> { data: u4:0 };
let result = dostuff(a);
assert_eq(result.data, u4:0);
}
error:
0113: pub fn dostuff<FIRST: u32, SECOND: u32, COMPUTED: u32 = {SECOND}>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^----^ TypeInferenceError: Parametric expression `SECOND` referred to `SECOND` which is not present in the parametric environment;
To Reproduce
Copy above and build.
Expected behavior
I expect this to compile without trouble, and that COMPUTED is a parametric argument equal to SECOND (which I would then use later in the parametric section or body of the function).
Additional context
There appears to be too-early parametric type erasure. Any parametric types not used to define a field of a struct are erased before function parametric type inference occurs.
This problem appears to be caused by the fact that SECOND is not used to define a field in struct SomeType. This can be demonstrated two ways:
- Change:
COMPUTED: u32 = {FIRST}. This compiles (because FIRST is used bydata). Now changedata: uN[SECOND]and it fails to compile (because FIRST is no longer used bydata.) - (don't do # 1 before doing:) Add another field to the struct, and define the field using
SECOND, e.g. likeunused: uN[SECOND]. Resolve the compile errors that result from this new field. Now it compiles.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
dslxDSLX (domain specific language) implementation / front-endDSLX (domain specific language) implementation / front-end
Type
Projects
Status
No status