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

Roof operator on string in template crashes compiler (Error: unhandled exception: sons is not accessible [FieldError]) #3545

Closed
singularperturbation opened this issue Nov 14, 2015 · 3 comments

Comments

@singularperturbation
Copy link
Contributor

Causes issue 70 (nim-lang/nimforum#70) in nim-lang/nimforum.
When you have a string as the result of an if statement in a template, the "roof" operator doesn't work correctly; based on following the stack trace it looks like it's trying to get openarray length and then crashes b/c the string is not an openarray / does not have sons.

Sample code

#test_roof_constexpr.nim
# This crashes the compiler, but not if doTest is a proc
template doTest(a: string,c: int) =
  var b =
    if c mod 2 == 0: a[^5 .. ^1]
    else: "SOME CONSTANT STRING"
  echo b

when isMainModule:
  doTest("THIS IS A TEST",5)

Compilation message

singularperturbation@localhost ~/nim> nim c test_roof_constexpr.nim
Hint: system [Processing]
Hint: test_roof_constexpr [Processing]
Traceback (most recent call last)
nim.nim(107)             nim
nim.nim(71)              handleCmdLine
main.nim(251)            mainCommand
main.nim(63)             commandCompileToC
modules.nim(221)         compileProject
modules.nim(169)         compileModule
passes.nim(203)          processModule
passes.nim(137)          processTopLevelStmt
sem.nim(460)             myProcess
sem.nim(446)             semStmtAndGenerateGenerics
transf.nim(886)          transformStmt
transf.nim(815)          processTransf
transf.nim(801)          transform
transf.nim(106)          transformSons
transf.nim(788)          transform
transf.nim(106)          transformSons
transf.nim(795)          transform
transf.nim(106)          transformSons
transf.nim(801)          transform
transf.nim(106)          transformSons
transf.nim(801)          transform
transf.nim(106)          transformSons
transf.nim(760)          transform
transf.nim(641)          transformCall
transf.nim(106)          transformSons
transf.nim(760)          transform
transf.nim(641)          transformCall
transf.nim(106)          transformSons
transf.nim(760)          transform
transf.nim(641)          transformCall
transf.nim(106)          transformSons
transf.nim(804)          transform
semfold.nim(693)         getConstExpr
semfold.nim(507)         magicCall
semfold.nim(295)         evalOp
ast.nim(1251)            sonsLen
system.nim(2533)         sysFatal
Error: unhandled exception: sons is not accessible [FieldError]
singularperturbation@localhost ~/nim>
@dom96
Copy link
Contributor

dom96 commented Nov 15, 2015

Compiles fine for me, are you using devel?

@singularperturbation
Copy link
Contributor Author

Very strange - I'm using the devel version of the compiler on amd64 linux.

singularperturbation@localhost ~/Nim> nim --version
Nim Compiler Version 0.12.1 (2015-11-13) [Linux: amd64]
Copyright (c) 2006-2015 by Andreas Rumpf

git hash: 0f7fdd8bf4d4f747f01c4d95ce64d96763286afc
active boot switches:
singularperturbation@localhost ~/Nim> uname -a
Linux localhost 3.10.18 #1 SMP Thu Oct 15 02:16:25 PDT 2015 x86_64 x86_64 x86_64 GNU/Linux
singularperturbation@localhost ~/Nim> 

As of writing, I think this has the latest commit from nim-lang/Nim

@singularperturbation
Copy link
Contributor Author

Debugging info from adding a renderTree to transform proc in transf.nim for the test file:
http://pastebin.com/wezLAjUP

Compiler does not give above error if built in release mode (for me).

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

No branches or pull requests

3 participants