Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gensym regression #10192

Closed
Araq opened this issue Jan 4, 2019 · 3 comments

Comments

Projects
None yet
3 participants
@Araq
Copy link
Member

commented Jan 4, 2019

This should compile, all involved templates are .dirty as far as I can tell.

import unicode, unittest

type my_string = distinct string

proc show(m: my_string) =
  echo m.string

template test_suite() =
  suite "test suite":
    setup:
      var s = "foo".my_string

    teardown:
      show(s)

    test "test1":
      check 1 == 1

test_suite()

@Araq Araq added the Regression label Jan 4, 2019

@Araq

This comment has been minimized.

Copy link
Member Author

commented Jan 4, 2019

Workaround:

import unicode, unittest

type my_string = distinct string

proc show(m: my_string) =
  echo m.string

template test_suite() {.dirty.} =
  suite "test suite":
    setup:
      var s = "foo".my_string

    teardown:
      show(s)

    test "test1":
      check 1 == 1

test_suite()
@LemonBoy

This comment has been minimized.

Copy link
Contributor

commented Feb 10, 2019

Caused by #9912.

Smaller reproducer
block:
  template nest(body) {.dirty.} =
    template p1(b1: untyped) {.dirty, used.} =
      template implp1: untyped {.dirty.} = b1
    template p2(b2: untyped) {.dirty, used.} =
      template implp2: untyped {.dirty.} = b2

    body
    implp1
    implp2

  template test() =
    nest:
      p1:
        var foo = "bar"
      p2:
        doAssert(foo.len == 3)

  test()

Calling test renames everything inside the body and the new logic in evalTemplateAux doesn't handle this case where we have nkSym belonging to another template instantiation (owner is nil and is not present in the mapping table): this means that evaluating p1 and p2 generate two fresh and disjoint symbols for foo.

I tried to fix it but got bored halfway trough, hopefully you'll find it more interesting :)

@krux02 krux02 self-assigned this Mar 28, 2019

@krux02

This comment has been minimized.

Copy link
Contributor

commented Mar 28, 2019

This is as far as the template expanion goes.

template p1(b1: untyped) {.dirty, used.} =
  template implp1(): untyped {.dirty.} =
    b1

template p2(b2: untyped) {.dirty, used.} =
  template implp2(): untyped {.dirty.} =
    b2
  
template implp1(): untyped {.dirty.} =
  var foo166013 = "bar"

template implp2(): untyped {.dirty.} =
  doAssert(foo166013.len ==
      3)

var foo166026 = "bar"
implp2()

Then in fails to expand implp2()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.