|
3 | 3 | from pathlib import Path
|
4 | 4 |
|
5 | 5 | from .utils import safezip, dataclass, SafeDict, listgen
|
6 |
| -from .interp_common import assert_type, exclude_fields, call_builtin_func, is_global_scope |
| 6 | +from .interp_common import assert_type, exclude_fields, call_builtin_func, is_global_scope, cast_to_python_string, cast_to_python_int |
7 | 7 | from .exceptions import InsufficientAccessLevel, ReturnSignal, Signal
|
8 | 8 | from . import exceptions as exc
|
9 | 9 | from . import pql_objects as objects
|
@@ -56,21 +56,32 @@ def resolve(state: State, col_def: ast.ColumnDef):
|
56 | 56 | assert not query
|
57 | 57 |
|
58 | 58 | if isinstance(coltype, objects.SelectedColumnInstance):
|
59 |
| - x = T.t_relation[coltype.type](rel={'table': coltype.parent.type, 'column': coltype.name, 'key': False}) |
| 59 | + table = coltype.parent.type |
| 60 | + if 'name' not in table.options: |
| 61 | + # XXX better test for persistence |
| 62 | + raise Signal.make(T.TypeError, col_def.type, "Tables provided as relations must be persistent.") |
| 63 | + |
| 64 | + x = T.t_relation[coltype.type](rel={'table': table, 'column': coltype.name, 'key': False}) |
60 | 65 | return x.replace(_nullable=coltype.type._nullable) # inherit is_nullable (TODO: use sumtypes?)
|
61 | 66 |
|
62 | 67 | elif coltype <= T.table:
|
| 68 | + if 'name' not in coltype.options: |
| 69 | + # XXX better test for persistence |
| 70 | + raise Signal.make(T.TypeError, col_def.type, "Tables provided as relations must be persistent.") |
| 71 | + |
63 | 72 | x = T.t_relation[T.t_id.as_nullable()](rel={'table': coltype, 'column': 'id', 'key': True})
|
64 | 73 | return x.replace(_nullable=coltype._nullable) # inherit is_nullable (TODO: use sumtypes?)
|
65 | 74 |
|
66 | 75 | return coltype(default=col_def.default)
|
67 | 76 |
|
68 | 77 | @dy
|
69 | 78 | def resolve(state: State, type_: ast.Type):
|
70 |
| - t = evaluate(state, type_.name) |
| 79 | + t = evaluate(state, type_.type_obj) |
71 | 80 | if isinstance(t, objects.TableInstance):
|
72 | 81 | t = t.type
|
73 |
| - assert t <= T.table |
| 82 | + |
| 83 | + if not isinstance(t, (Type, objects.SelectedColumnInstance)): |
| 84 | + raise Signal.make(T.TypeError, type_, f"Expected type in column definition. Instead got '{t}'") |
74 | 85 |
|
75 | 86 | if type_.nullable:
|
76 | 87 | t = t.as_nullable()
|
@@ -207,7 +218,7 @@ def _execute(state: State, insert_rows: ast.InsertRows):
|
207 | 218 |
|
208 | 219 | rval = evaluate(state, insert_rows.value)
|
209 | 220 |
|
210 |
| - assert_type(rval.type, T.table, state, insert_rows, '+=') |
| 221 | + assert_type(rval.type, T.table, insert_rows, '+=') |
211 | 222 |
|
212 | 223 | return _copy_rows(state, insert_rows.name, rval)
|
213 | 224 |
|
@@ -602,7 +613,7 @@ def apply_database_rw(state: State, o: ast.One):
|
602 | 613 | return new_value_instance(row)
|
603 | 614 |
|
604 | 615 | assert table.type <= T.table
|
605 |
| - assert_type(table.type, T.table, state, o, 'one') |
| 616 | + assert_type(table.type, T.table, o, 'one') |
606 | 617 | d = {k: new_value_instance(v, table.type.elems[k], True) for k, v in row.items()}
|
607 | 618 | return objects.RowInstance(rowtype, d)
|
608 | 619 |
|
@@ -691,7 +702,7 @@ def apply_database_rw(state: State, new: ast.NewRows):
|
691 | 702 | # XXX Is it always TableInstance? Just sometimes? What's the transition here?
|
692 | 703 | obj = obj.type
|
693 | 704 |
|
694 |
| - assert_type(obj, T.table, state, new, "'new' expected an object of type '%s', instead got '%s'") |
| 705 | + assert_type(obj, T.table, new, "'new' expected an object of type '%s', instead got '%s'") |
695 | 706 |
|
696 | 707 | arg ,= new.args
|
697 | 708 |
|
@@ -795,7 +806,7 @@ def create_exception(state, msg):
|
795 | 806 |
|
796 | 807 | table = obj
|
797 | 808 | # TODO assert tabletype is a real table and not a query (not transient), otherwise new is meaningless
|
798 |
| - assert_type(table.type, T.table, state, new, "'new' expected an object of type '%s', instead got '%s'") |
| 809 | + assert_type(table.type, T.table, new, "'new' expected an object of type '%s', instead got '%s'") |
799 | 810 |
|
800 | 811 | cons = TableConstructor.make(table.type)
|
801 | 812 | matched = cons.match_params(state, new.args)
|
|
0 commit comments