Closed WiseIndian closed 4 years ago
@liufengyun
Fengyun I think I need your help on an issue I had. I was stuck with the way to compare the type of the argument to the yieldval with the type T
of the coroutine[T]
function. At first I thought I could extract the some value of type Type
for both T
and the argument of the yieldval and then
pass it to a method from dotty.
I found that in the same packages where TypeComparer
is defined one can use ctx.typeComparer.isSubType(t1, t2)
where t1
and t2
are of type. Do you know if there is a similar method outside that can be used by users of macros?
Sorry, I missed the message, @LeDevDuDimanche . It would be nice if you send emails if I didn't respond in 2 days.
All APIs in the following file are helpful:
https://github.com/lampepfl/dotty/blob/master/library/src/scala/tasty/Reflection.scala#L1628
Thank you :)
82aa52e
For the scheme to work, we need to implement a checker:
yieldVal
has the correct typeThis will be the principled way to implement DSLs, while most libraries are not doing it, including async-await, etc. As a result, they get all kinds of bug reports, because they didn't specify the syntax of the DSL formally, and only perform limited ad-hoc check of the syntax and types of a DSL program.
By checking the code in the coroutine body, friendly error message can be reported to users at compile-time, instead of frustration at runtime.