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

new gensym handling #11985

Merged
merged 14 commits into from
Aug 23, 2019
Merged

new gensym handling #11985

merged 14 commits into from
Aug 23, 2019

Conversation

Araq
Copy link
Member

@Araq Araq commented Aug 20, 2019

  • will fix many template bugs, eventually.

doc/manual.rst Outdated Show resolved Hide resolved
@Araq Araq merged commit b07694c into devel Aug 23, 2019
@Araq Araq deleted the araq-new-gensym branch August 23, 2019 14:15
expectArg(conf, switch, arg, pass, info)
case arg
of "0.19":
conf.globalOptions.incl optNimV019
Copy link
Member

@timotheecour timotheecour Aug 23, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is optNimV019 related to nimv019 in config/nim.cfg? as i understand this only affects gensym handling, so maybe it should be in the flag name, eg --genSymVersion, as there could be other transition flags that should be settable independently; eg if in future you'll need a transition between 1.0 and 1.1 that's totally unrelated to gensym handling

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are moving over to "trunk based" development, that's why. These transition switches will be collected under useVersion.

@timotheecour
Copy link
Member

timotheecour commented Aug 23, 2019

I thought this PR would fix following bugs but apparently it doesn't, and maybe it can't as there's inherent ambiguity:

type Foo = object
  b: int
proc bar(b = 12) = discard

template fun(b): untyped =
  var x: Foo
  # each line here would give an error
  var x0 = Foo(b: 3)
  bar(b=32)
  x.b = 5
  echo x.b

template fun2(b2): untyped =
  var x = Foo(b: 3)
  x.b = 5
  echo x.b
  echo b2

proc main()=
  fun2(14) # ok
  fun(14) # Error: identifier expected, but found '14'

main()

IMO we should reopen #8899, it's a fool proof solution:

template fun(b): untyped =
  var x: Foo
  var x0 = Foo(`b`: 3)
  bar(`b`=32)
  x.`b` = 5
  x.b = 15 # this one actually means: substitute (eg if user passes an identifier as b, it will work as intended)
  echo x.`b`

since there's no need to quote valid identifiers (such as template arguments), there's no loss of generality.
more examples showing user can still pass a quoted ident as argument:

template baz(field) =
  field(32)
baz(`x=`) # will call `x=`(32)
baz(bar) # will call bar(32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants