WiseIndian / Coroutines-for-Scala-3

3 stars 2 forks source link

Create a checker #6

Closed WiseIndian closed 4 years ago

WiseIndian commented 4 years ago

For the scheme to work, we need to implement a checker:

  1. check the syntax, as specified
  2. check yieldVal has the correct type

This 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.

WiseIndian commented 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?

liufengyun commented 4 years ago

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

WiseIndian commented 4 years ago

Thank you :)

WiseIndian commented 4 years ago

82aa52e