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

when a() and b() should short-circuit semcheck #13502

Closed
timotheecour opened this issue Feb 26, 2020 · 3 comments
Closed

when a() and b() should short-circuit semcheck #13502

timotheecour opened this issue Feb 26, 2020 · 3 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Feb 26, 2020

when declared(Foo) and T is Foo: fails but there's no reason to: and should short-circuit semcheck of 2nd arg when 1st arg is false

Example

type T = int
static: doAssert not declared(Foo) # ok
# all these fail with: Error: undeclared identifier: 'Foo'
when declared(Foo) and T is Foo: discard
when false and T is Foo: discard
const isFoo1 = declared(Foo) and (T is Foo)
const isFoo2 = false and (T is Foo)

Current Output

Error: undeclared identifier: 'Foo'

Expected Output

works.

in particular, this is useful for eg in generic code in include files etc where you need to specialize for some types, but these may not be present

workaround

  template ctAnd(a, b): bool =
    when a:
      when b: true
      else: false
    else: false

  type T = int
  type Bar = int
  static: doAssert not ctAnd(declared(Foo), T is Foo)
  static: doAssert ctAnd(declared(Bar), T is Bar)
  static: doAssert not ctAnd(declared(Bar), T isnot Bar)

Additional Information

@timotheecour timotheecour changed the title when declared(Foo) and T is Foo: fails: const bool should short-circuit evaluation when a() and b() should short-circuit evaluation Feb 26, 2020
@krux02
Copy link
Contributor

krux02 commented Feb 26, 2020

what you want is short circuit semantic checking not short circuit evaluation. The later one already happens. And btw -1 for the feature request.

@timotheecour timotheecour changed the title when a() and b() should short-circuit evaluation when a() and b() should short-circuit semcheck Feb 26, 2020
@Araq
Copy link
Member

Araq commented Feb 26, 2020

This is a bug, not a feature request. In fact, it's a duplicate of some other bug report.

timotheecour added a commit to timotheecour/Nim that referenced this issue Feb 29, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Feb 29, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Feb 29, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Mar 1, 2020
timotheecour added a commit to timotheecour/Nim that referenced this issue Mar 2, 2020
@Araq
Copy link
Member

Araq commented Mar 2, 2020

I take it back, I misunderstood this problem. This is not a bug, the sem'checking for and follows Nim's basic rules and it's overloaded even, so no ``untyped´`-like behaviour is desired.

@Araq Araq closed this as completed Mar 2, 2020
@Araq Araq added the Won't Fix label Mar 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants