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

fix term rewriting with sideeffect #19410

Merged
merged 3 commits into from
Jan 19, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/parampatterns.nim
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,11 @@ proc checkForSideEffects*(n: PNode): TSideEffectAnalysis =
let s = op.sym
if sfSideEffect in s.flags:
return seSideEffect
# assume no side effect:
result = seNoSideEffect
elif tfNoSideEffect in op.typ.flags:
result = seNoSideEffect
else:
# assume side effect:
result = seSideEffect
elif tfNoSideEffect in op.typ.flags:
# indirect call without side effects:
result = seNoSideEffect
Expand Down
19 changes: 19 additions & 0 deletions tests/template/t6217.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
discard """
output: '''
start
side effect!
end
'''
"""

# bug #6217

template optMul{`*`(a, 2)}(a: int{noSideEffect}): int = a+a

proc f(): int =
echo "side effect!"
result = 55

echo "start"
doAssert f() * 2 == 110
echo "end"
3 changes: 0 additions & 3 deletions tests/template/template_various.nim
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ block pattern_with_converter:

doAssert floatDouble(5) == 10.0

ringabout marked this conversation as resolved.
Show resolved Hide resolved



block procparshadow:
template something(name: untyped) =
proc name(x: int) =
Expand Down