liufengyun / gestalt

gestalt : portable and solid macros for Scala
https://github.com/scalacenter/macros
31 stars 3 forks source link

hygiene problem #79

Open liufengyun opened 7 years ago

liufengyun commented 7 years ago

Hygiene is a common problem in macros.

We've some initial design ideas about hygiene here:

https://github.com/liufengyun/gestalt/pull/77#pullrequestreview-38177513

Generally, hygiene becomes a problem when a name either in user-program or meta-program changes its originally intended meaning. There are mainly three cases:

liufengyun commented 7 years ago

Note that https://github.com/liufengyun/gestalt/pull/81 provides a solution to the 2nd problem above, both for syntatic macros and semantic macros.

It seems there's no simple way to do better for the 1st and 3rd problem, especially for syntactic macros.

liufengyun commented 7 years ago

During semester project presentation, @sjrd mentioned the current approach to hygiene will cause inconvenience:

def macro: Unit = {
  q"""
      val x = 4
      println(x)
  """
}

The code above will not type check, unless gestalt.options.unsafe is imported, which is a little unfortunate.