From: Stefano Rivera <stefanor@debian.org>
Date: Sat, 19 Dec 2020 11:07:52 -0800
Subject: Core: Fix type annotation scoping crash

Bug-upstream: https://foss.heptapod.net/pypy/pypy/-/issues/3355
Origin: upstream, https://foss.heptapod.net/pypy/pypy/-/commit/14ff4a357d9404e5a1bf5ae226a7e86b15920d47
---
 pypy/interpreter/astcompiler/symtable.py           |  2 +-
 pypy/interpreter/astcompiler/test/test_compiler.py | 11 +++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/pypy/interpreter/astcompiler/symtable.py b/pypy/interpreter/astcompiler/symtable.py
index 6f2bc11..5385a2d 100644
--- a/pypy/interpreter/astcompiler/symtable.py
+++ b/pypy/interpreter/astcompiler/symtable.py
@@ -444,7 +444,7 @@ class SymtableBuilder(ast.GenericASTVisitor):
             if assign.simple:
                 scope |= SYM_ANNOTATED
             if assign.value:
-                scope |= SYM_USED
+                scope |= SYM_ASSIGNED
             if scope:
                 self.note_symbol(name, scope)
         else:
diff --git a/pypy/interpreter/astcompiler/test/test_compiler.py b/pypy/interpreter/astcompiler/test/test_compiler.py
index 5836a8f..98602e1 100644
--- a/pypy/interpreter/astcompiler/test/test_compiler.py
+++ b/pypy/interpreter/astcompiler/test/test_compiler.py
@@ -1276,6 +1276,17 @@ class TestCompiler(BaseTestCompiler):
             x = [y for (x, y) in dis.findlinestarts(co)]
         """, 'x', [4]
 
+    def test_bug_crash_annotations(self):
+        yield self.simple_test, """\
+            def func():
+                bar = None
+
+                class Foo:
+                    bar: int = 0  # removing type annotation make the error disappear
+
+                    def get_bar(self):
+                        return bar
+        """, '1', 1
 
 class TestCompilerRevDB(BaseTestCompiler):
     spaceconfig = {"translation.reverse_debugger": True}
