@@ -8,17 +8,17 @@ use partiql_types::{ArrayType, BagType, PartiqlType, StructType, TypeKind};
88
99#[ derive( Debug , Clone ) ]
1010#[ allow( dead_code) ]
11- pub struct AstStaticTyper < ' c > {
11+ pub struct AstPartiqlTyper < ' c > {
1212 id_stack : Vec < NodeId > ,
1313 container_stack : Vec < Vec < PartiqlType > > ,
1414 errors : Vec < AstTransformError > ,
1515 type_map : AstTypeMap < PartiqlType > ,
1616 catalog : & ' c dyn Catalog ,
1717}
1818
19- impl < ' c > AstStaticTyper < ' c > {
19+ impl < ' c > AstPartiqlTyper < ' c > {
2020 pub fn new ( catalog : & ' c dyn Catalog ) -> Self {
21- AstStaticTyper {
21+ AstPartiqlTyper {
2222 id_stack : Default :: default ( ) ,
2323 container_stack : Default :: default ( ) ,
2424 errors : Default :: default ( ) ,
@@ -47,7 +47,7 @@ impl<'c> AstStaticTyper<'c> {
4747 }
4848}
4949
50- impl < ' c , ' ast > Visitor < ' ast > for AstStaticTyper < ' c > {
50+ impl < ' c , ' ast > Visitor < ' ast > for AstPartiqlTyper < ' c > {
5151 fn enter_ast_node ( & mut self , id : NodeId ) -> Traverse {
5252 self . id_stack . push ( id) ;
5353 Traverse :: Continue
@@ -116,9 +116,9 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
116116 Lit :: NationalCharStringLit ( _) => TypeKind :: String ,
117117 Lit :: BitStringLit ( _) => todo ! ( ) ,
118118 Lit :: HexStringLit ( _) => todo ! ( ) ,
119- Lit :: StructLit ( _) => TypeKind :: Struct ( StructType :: unconstrained ( ) ) ,
120- Lit :: ListLit ( _) => TypeKind :: Array ( ArrayType :: array ( ) ) ,
121- Lit :: BagLit ( _) => TypeKind :: Bag ( BagType :: bag ( ) ) ,
119+ Lit :: StructLit ( _) => TypeKind :: Struct ( StructType :: new_any ( ) ) ,
120+ Lit :: ListLit ( _) => TypeKind :: Array ( ArrayType :: new_any ( ) ) ,
121+ Lit :: BagLit ( _) => TypeKind :: Bag ( BagType :: new_any ( ) ) ,
122122 Lit :: TypedLit ( _, _) => todo ! ( ) ,
123123 } ;
124124
@@ -161,7 +161,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
161161 }
162162 }
163163
164- let ty = PartiqlType :: new_struct ( StructType :: unconstrained ( ) ) ;
164+ let ty = PartiqlType :: new_struct ( StructType :: new_any ( ) ) ;
165165 self . type_map . insert ( id, ty. clone ( ) ) ;
166166
167167 if let Some ( c) = self . container_stack . last_mut ( ) {
@@ -184,7 +184,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
184184 self . container_stack . pop ( ) ;
185185
186186 let id = * self . current_node ( ) ;
187- let ty = PartiqlType :: new_bag ( BagType :: bag ( ) ) ;
187+ let ty = PartiqlType :: new_bag ( BagType :: new_any ( ) ) ;
188188
189189 self . type_map . insert ( id, ty. clone ( ) ) ;
190190 if let Some ( s) = self . container_stack . last_mut ( ) {
@@ -206,7 +206,7 @@ impl<'c, 'ast> Visitor<'ast> for AstStaticTyper<'c> {
206206 self . container_stack . pop ( ) ;
207207
208208 let id = * self . current_node ( ) ;
209- let ty = PartiqlType :: new_array ( ArrayType :: array ( ) ) ;
209+ let ty = PartiqlType :: new_array ( ArrayType :: new_any ( ) ) ;
210210
211211 self . type_map . insert ( id, ty. clone ( ) ) ;
212212 if let Some ( s) = self . container_stack . last_mut ( ) {
@@ -221,8 +221,8 @@ mod tests {
221221 use super :: * ;
222222 use assert_matches:: assert_matches;
223223 use partiql_ast:: ast;
224- use partiql_catalog:: PartiqlCatalog ;
225- use partiql_types:: { PartiqlType , TypeKind } ;
224+ use partiql_catalog:: { PartiqlCatalog , TypeEnvEntry } ;
225+ use partiql_types:: { PartiqlType , StructConstraint , StructField , TypeKind } ;
226226
227227 #[ test]
228228 fn simple_test ( ) {
@@ -244,22 +244,24 @@ mod tests {
244244
245245 #[ test]
246246 fn simple_err_test ( ) {
247- assert ! ( type_statement( "{'a': 1, a.b: 3}" ) . is_err( ) ) ;
247+ assert ! ( type_statement( "{'a': 1, a.b: 3}" , & PartiqlCatalog :: default ( ) ) . is_err( ) ) ;
248248 }
249249
250250 fn run_literal_test ( q : & str ) -> TypeKind {
251- let out = type_statement ( q) . expect ( "type map" ) ;
251+ let out = type_statement ( q, & PartiqlCatalog :: default ( ) ) . expect ( "type map" ) ;
252252 let values: Vec < & PartiqlType > = out. values ( ) . collect ( ) ;
253253 values. last ( ) . unwrap ( ) . kind ( ) . clone ( )
254254 }
255255
256- fn type_statement ( q : & str ) -> Result < AstTypeMap < PartiqlType > , AstTransformationError > {
256+ fn type_statement (
257+ q : & str ,
258+ catalog : & dyn Catalog ,
259+ ) -> Result < AstTypeMap < PartiqlType > , AstTransformationError > {
257260 let parsed = partiql_parser:: Parser :: default ( )
258261 . parse ( q)
259262 . expect ( "Expect successful parse" ) ;
260263
261- let catalog = PartiqlCatalog :: default ( ) ;
262- let typer = AstStaticTyper :: new ( & catalog) ;
264+ let typer = AstPartiqlTyper :: new ( catalog) ;
263265 if let ast:: Expr :: Query ( q) = parsed. ast . as_ref ( ) {
264266 typer. type_nodes ( & q)
265267 } else {
0 commit comments