Solve the annoying `C with AnyRef` problem with contexts
Closed this issue · 1 comments
LPTK commented
Sometimes one still encounters annoying errors saying a context should be C with AnyRef
instead of just C
.
This basically happens when using constructs that return IR[T,{}]
, such as Const(123)
because Const
is defined as [T: IRType](v: T): IR[T,{}]
. For example:
def foo[C](x: IR[Int, C]): IR[Int, C] = ir"$x + ${Const(123)}"
This code fails to compile with:
Error:(37, 56) type mismatch;
found : squid.TestDSL.IR[Int,AnyRef with C]
required: squid.TestDSL.Predef.IR[Int,C]
(which expands to) squid.TestDSL.IR[Int,C]
def foo[C](x: IR[Int, C]): IR[Int, C] = ir"$x + ${Const(123)}"
LPTK commented
Solved in https://github.com/epfldata/sc/commit/3c4f3fa91f0e336d3f3eed6f2662b2cbb3f2cf47
We now remove AnyRef
types from inferred contexts.
Using {}
for the empty context is debatable (though it does look better than Any
), but at least now it should cause far fewer problems.