xls
xls copied to clipboard
parameter func should be able to return explicit parametric literal
It seems that attempting to return an explicit foreign parametric type literal from a parametric func:
import apfloat;
fn some_apfloat<F_EXP_SZ: u32, F_FRACTION_SZ: u32> () -> apfloat::APFloat<F_EXP_SZ, F_FRACTION_SZ> {
apfloat::APFloat<F_EXP_SZ, F_FRACTION_SZ>{ sign: u1:1, bexp: uN[F_EXP_SZ]:2, fraction: uN[F_FRACTION_SZ]:3 }
}
currently trigger the following error:
0006: apfloat::APFloat<F_EXP_SZ, F_FRACTION_SZ>{ sign: u1:1, bexp: uN[F_EXP_SZ]:2, fraction: uN[F_FRACTION_SZ]:3 }
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ ParseError: Expected '(', got '{': Expected a '(' after parametrics for function invocation.
This can be worked around by introducing an intermediate type alias:
fn some_apfloat<F_EXP_SZ: u32, F_FRACTION_SZ: u32> () -> apfloat::APFloat<F_EXP_SZ, F_FRACTION_SZ> {
type F = apfloat::APFloat<F_EXP_SZ, F_FRACTION_SZ>;
F{ sign: u1:1, bexp: uN[F_EXP_SZ]:2, fraction: uN[F_FRACTION_SZ]:3 }
}
or dropping the type parameters from the literal altogether:
fn some_apfloat<F_EXP_SZ: u32, F_FRACTION_SZ: u32> () -> apfloat::APFloat<F_EXP_SZ, F_FRACTION_SZ> {
apfloat::APFloat{ sign: u1:1, bexp: uN[F_EXP_SZ]:2, fraction: uN[F_FRACTION_SZ]:3 }
}