Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-compiler
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
typon
typon-compiler
Commits
43829e2b
Commit
43829e2b
authored
Jul 07, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow empty AnnAssigns (var decls without values)
parent
68b42e9e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
trans/transpiler/phases/emit_cpp/block.py
trans/transpiler/phases/emit_cpp/block.py
+8
-5
trans/transpiler/phases/typing/block.py
trans/transpiler/phases/typing/block.py
+13
-0
No files found.
trans/transpiler/phases/emit_cpp/block.py
View file @
43829e2b
...
...
@@ -140,9 +140,12 @@ class BlockVisitor(NodeVisitor):
yield
";"
def
visit_AnnAssign
(
self
,
node
:
ast
.
AnnAssign
)
->
Iterable
[
str
]:
if
node
.
value
is
None
:
raise
NotImplementedError
(
node
,
"empty value"
)
yield
from
self
.
visit_lvalue
(
node
.
target
)
yield
" = "
yield
from
self
.
expr
().
visit
(
node
.
value
)
# if node.value is None:
# raise NotImplementedError(node, "empty value")
yield
from
self
.
visit_lvalue
(
node
.
target
,
node
.
is_declare
)
if
node
.
value
:
yield
" = "
yield
from
self
.
expr
().
visit
(
node
.
value
)
yield
";"
trans/transpiler/phases/typing/block.py
View file @
43829e2b
...
...
@@ -56,6 +56,19 @@ class ScoperBlockVisitor(ScoperVisitor):
ty
=
self
.
get_type
(
node
.
value
)
try
:
node
.
is_declare
=
self
.
visit_assign_target
(
target
,
ty
)
except
IncompatibleTypesError
as
e
:
raise
IncompatibleTypesError
(
f"`
{
ast
.
unparse
(
node
)
}
:
{
e
}
"
)
from
e
def
visit_AnnAssign
(
self
,
node
:
ast
.
AnnAssign
):
if
node
.
value
is
not
None
:
raise
NotImplementedError
(
node
)
if
node
.
simple
!=
1
:
raise
NotImplementedError
(
node
)
if
not
isinstance
(
node
.
target
,
ast
.
Name
):
raise
NotImplementedError
(
node
)
ty
=
self
.
visit_annotation
(
node
.
annotation
)
try
:
node
.
is_declare
=
self
.
visit_assign_target
(
node
.
target
,
ty
)
except
IncompatibleTypesError
as
e
:
raise
IncompatibleTypesError
(
f"`
{
ast
.
unparse
(
node
)
}
:
{
e
}
"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment