hpython-0.1: Syntax tree and DSL for Python

Copyright(C) CSIRO 2017-2018
LicenseBSD3
MaintainerIsaac Elliott <isaace71295@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Language.Python.Validate.Scope.Error

Description

 

Documentation

data ScopeError a Source #

Constructors

FoundNonlocal a

Using nonlocal to modify function scopes makes scope checking intractible

FoundGlobal a

Using global to add identifiers to the global scope makes scope checking intractible

DeletedIdent a

Using del to remove identifiers from scope makes scope checking intractible

FoundDynamic a (Ident '[] a)

Variable assignments deep in control flow can modify the scope outside the control flow. For example:

if a:
    x = 0
else:
    pass

print(x)

x will be in scope if the True branch was entered, but not if the False branch was entered. This kind of behaviour makes scope checking intractible, so programs like this are considered scope errors.

NotInScope (Ident '[] a)

An identifier is not in scope

BadShadowing (Ident '[] a)

For loops don't execute in a fresh scope, so if the counter of the loop shadows a variable, then that variable will be mutated.

e.g.

x = 0
for x in 1, 2, 3:
   pass
print(x)

outputs 3

This error occurs when we spot this pattern.

Instances
Eq a => Eq (ScopeError a) Source # 
Instance details

Defined in Language.Python.Validate.Scope.Error

Methods

(==) :: ScopeError a -> ScopeError a -> Bool #

(/=) :: ScopeError a -> ScopeError a -> Bool #

Show a => Show (ScopeError a) Source # 
Instance details

Defined in Language.Python.Validate.Scope.Error

AsScopeError (ScopeError a) a Source # 
Instance details

Defined in Language.Python.Validate.Scope.Error

Methods

_ScopeError :: Prism' (ScopeError a) (ScopeError a) Source #

_FoundNonlocal :: Prism' (ScopeError a) a Source #

_FoundGlobal :: Prism' (ScopeError a) a Source #

_DeletedIdent :: Prism' (ScopeError a) a Source #

_FoundDynamic :: Prism' (ScopeError a) (a, Ident [] a) Source #

_NotInScope :: Prism' (ScopeError a) (Ident [] a) Source #

_BadShadowing :: Prism' (ScopeError a) (Ident [] a) Source #

class AsScopeError r a | r -> a where Source #

Minimal complete definition

_ScopeError

Methods

_ScopeError :: Prism' r (ScopeError a) Source #

_FoundNonlocal :: Prism' r a Source #

_FoundGlobal :: Prism' r a Source #

_DeletedIdent :: Prism' r a Source #

_FoundDynamic :: Prism' r (a, Ident ('[] :: [Type]) a) Source #

_NotInScope :: Prism' r (Ident ('[] :: [Type]) a) Source #

_BadShadowing :: Prism' r (Ident ('[] :: [Type]) a) Source #