sourcery-ai / sourcery

Instant AI code reviews
https://sourcery.ai
MIT License
1.5k stars 65 forks source link

Refactoring `hoist-if-from-if` produces undefined errors #339

Open lanvent opened 1 year ago

lanvent commented 1 year ago

Checklist

Description

hoist-if-from-if may produce undefined errors.

Code snippet that reproduces issue

image

It moves a local variable out, causing an undefined error.

Debug Information

IDE Version: Command Line

Sourcery Version: Sourcery 1.2.0

Operating system and Version: windows 11

lanvent commented 1 year ago

another bug: one item is not moved into initialization.

image

channel\wechatmp\reply.py:14-15 merge-dict-assign
channel\wechatmp\reply.py:14-16 merge-dict-assign
channel\wechatmp\reply.py:14-17 merge-dict-assign
channel\wechatmp\reply.py:14 dict-literal
channel\wechatmp\reply.py:34-35 merge-dict-assign
channel\wechatmp\reply.py:34-36 merge-dict-assign
channel\wechatmp\reply.py:34-37 merge-dict-assign
channel\wechatmp\reply.py:34 dict-literal
ruancomelli commented 1 year ago

Hello, @lanvent, thanks for reporting those bugs! I'll investigate both of them and try to get them fixed as soon as possible. I moved the second bug report to https://github.com/sourcery-ai/sourcery/issues/342 for us to better keep track of it.