Code Monkey home page Code Monkey logo

Comments (3)

litlighilit avatar litlighilit commented on May 23, 2024

A clearer demo:

template valueOr*(def: untyped): int =
  when false:
    # Comment line below to make it work
    template error(): int {.gensym.} = discard
    discard
  else:
    template error(): int {.inject.} = 1
  def

let rErrV = valueOr error

It seems the symbol capture doesn't cover edge cases, when it comes to gensym

from nim.

litlighilit avatar litlighilit commented on May 23, 2024

In addition,

maybe there is another factor:

template valueOr*(def: untyped): int =
  template error(): int {.gensym.} = 1
  def

let rErrV = valueOr error

gensym is not considered when lookup

from nim.

metagn avatar metagn commented on May 23, 2024

Culprit is maybe this?

if s.owner == c.owner and (s.kind == skParam or sfGenSym in s.flags):

The gensym template is added to scope here and the injected template declaration finds it and reuses the symbol? Presumably to allow overloading the gensym'd symbol since adding gensym again defines a different symbol, even though omitting gensym implies inject for routines. Then again why does gensym again define a different symbol when we only get to use one at a time in the template?

We could move the gensym reuse logic inside the logic for when gensym is given, if this breaks code we could allow opting out of the symbol reuse on an explicit inject.

This is all letting alone the logic of actually using error inside the template after the when block, also I'm speculating about all this from my phone so I might be wrong.

from nim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.