Can't use a parametric function in another function's parametric list
- Dominant language
- C++
- Stars
- 1.9k
- Forks
- 283
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 135
Description
**Describe the bug**
Motivating example: I want to use `apfloat::min_normal_exp()` to define a new `apfloat:: min_subnormal_exp<...>`. My new function wants to return the smallest bitwidth that fits the integer returned. So naturally I call `apfloat::min_normal_exp` from within the parameter list to compute the returned bitwidth. But that's not working.
**To Reproduce**
Try to compile this:
```
// Returns the unbiased exponent of the smallest subnormal number representable by an apfloat
// with the given number of exponent and fraction bits.
pub fn min_subnormal_exp
() as s32 - FRACTION_SZ as s32 - s32:1)) as u32) +
u32:1} > () -> sN[R] {
(apfloat::min_normal_exp() as s32 - FRACTION_SZ as s32) as sN[R]
}
#[test]
fn test_min_subnormal_exp() {
assert_eq(
min_subnormal_exp(),
s9:-149);
}
```
and observe error:
```
1754: u32 = {
1755: std::clog2(
1756: (-(apfloat::min_normal_exp() as s32 - FRACTION_SZ as s32 - s32:1)) as u32) +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^----^ TypeInferenceError: uN[32] Parametric expression `EXP_SZ` was not constexpr -- parametric values must be compile-time constants
1757: u32:1} > () -> sN[R] {
```
**Expected behavior**
It should work without type error.
Contributor guide
Assessment
This issue has not been assessed yet.