Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
T
typon-concurrency
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
Xavier Thompson
typon-concurrency
Commits
0f328ac7
Commit
0f328ac7
authored
Jun 20, 2023
by
Tom Niget
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add type checking to for-loops
parent
a32ef1be
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
2 deletions
+14
-2
trans/stdlib/__init__.py
trans/stdlib/__init__.py
+2
-0
trans/transpiler/phases/typing/block.py
trans/transpiler/phases/typing/block.py
+12
-2
No files found.
trans/stdlib/__init__.py
View file @
0f328ac7
...
...
@@ -36,6 +36,8 @@ class str:
def
format
(
self
,
*
args
)
->
Self
:
...
def
encode
(
self
,
encoding
:
Self
)
->
bytes
:
...
def
__len__
(
self
)
->
int
:
...
def
__add__
(
self
,
other
:
Self
)
->
Self
:
...
def
__mul__
(
self
,
other
:
int
)
->
Self
:
...
class
bytes
:
def
decode
(
self
,
encoding
:
str
)
->
str
:
...
...
...
trans/transpiler/phases/typing/block.py
View file @
0f328ac7
...
...
@@ -136,8 +136,18 @@ class ScoperBlockVisitor(ScoperVisitor):
scope
=
self
.
scope
.
child
(
ScopeKind
.
FUNCTION_INNER
)
node
.
inner_scope
=
scope
assert
isinstance
(
node
.
target
,
ast
.
Name
)
scope
.
vars
[
node
.
target
.
id
]
=
VarDecl
(
VarKind
.
LOCAL
,
TypeVariable
())
self
.
expr
().
visit
(
node
.
iter
)
var_var
=
TypeVariable
()
scope
.
vars
[
node
.
target
.
id
]
=
VarDecl
(
VarKind
.
LOCAL
,
var_var
)
seq_type
=
self
.
expr
().
visit
(
node
.
iter
)
try
:
iter_type
=
seq_type
.
methods
[
"__iter__"
].
return_type
except
:
raise
IncompatibleTypesError
(
f"
{
seq_type
}
is not iterable"
)
try
:
next_type
=
iter_type
.
methods
[
"__next__"
].
return_type
except
:
raise
IncompatibleTypesError
(
f"iter(
{
iter_type
}
) is not an iterator"
)
var_var
.
unify
(
next_type
)
body_scope
=
scope
.
child
(
ScopeKind
.
FUNCTION_INNER
)
body_visitor
=
ScoperBlockVisitor
(
body_scope
,
self
.
root_decls
)
body_visitor
.
visit_block
(
node
.
body
)
...
...
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