@@ -6,6 +6,7 @@ use alloc::{
66} ;
77use core:: num:: NonZeroU32 ;
88
9+ use crate :: common:: wgsl:: TypeContext ;
910use crate :: front:: wgsl:: error:: { Error , ExpectedToken , InvalidAssignmentType } ;
1011use crate :: front:: wgsl:: index:: Index ;
1112use crate :: front:: wgsl:: parse:: number:: Number ;
@@ -388,6 +389,30 @@ pub struct ExpressionContext<'source, 'temp, 'out> {
388389 expr_type : ExpressionContextType < ' temp , ' out > ,
389390}
390391
392+ impl TypeContext for ExpressionContext < ' _ , ' _ , ' _ > {
393+ fn lookup_type ( & self , handle : Handle < crate :: Type > ) -> & crate :: Type {
394+ & self . module . types [ handle]
395+ }
396+
397+ fn type_name ( & self , handle : Handle < crate :: Type > ) -> & str {
398+ self . module . types [ handle]
399+ . name
400+ . as_deref ( )
401+ . unwrap_or ( "{anonymous type}" )
402+ }
403+
404+ fn write_override < W : core:: fmt:: Write > (
405+ & self ,
406+ handle : Handle < crate :: Override > ,
407+ out : & mut W ,
408+ ) -> core:: fmt:: Result {
409+ match self . module . overrides [ handle] . name {
410+ Some ( ref name) => out. write_str ( name) ,
411+ None => write ! ( out, "{{anonymous override {handle:?}}}" ) ,
412+ }
413+ }
414+ }
415+
391416impl < ' source , ' temp , ' out > ExpressionContext < ' source , ' temp , ' out > {
392417 #[ allow( dead_code) ]
393418 fn as_const ( & mut self ) -> ExpressionContext < ' source , ' _ , ' _ > {
@@ -1256,8 +1281,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
12561281 if !explicit_inner. equivalent ( init_inner, & ectx. module . types ) {
12571282 return Err ( Box :: new ( Error :: InitializationTypeMismatch {
12581283 name : name. span ,
1259- expected : explicit_inner . to_wgsl ( & ectx. module . to_ctx ( ) ) ,
1260- got : init_inner . to_wgsl ( & ectx. module . to_ctx ( ) ) ,
1284+ expected : ectx. type_inner_to_string ( explicit_inner ) ,
1285+ got : ectx. type_inner_to_string ( init_inner ) ,
12611286 } ) ) ;
12621287 }
12631288 ty = explicit_ty;
@@ -1487,11 +1512,10 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
14871512 . inner
14881513 . equivalent ( & ctx. module . types [ init_ty] . inner , & ctx. module . types )
14891514 {
1490- let gctx = & ctx. module . to_ctx ( ) ;
14911515 return Err ( Box :: new ( Error :: InitializationTypeMismatch {
14921516 name : l. name . span ,
1493- expected : ty . to_wgsl ( gctx ) ,
1494- got : init_ty . to_wgsl ( gctx ) ,
1517+ expected : ctx . type_to_string ( ty ) ,
1518+ got : ctx . type_to_string ( init_ty ) ,
14951519 } ) ) ;
14961520 }
14971521 }
@@ -2192,11 +2216,10 @@ impl<'source, 'temp> Lowerer<'source, 'temp> {
21922216 crate :: TypeInner :: Vector { scalar, .. } => scalar,
21932217 _ => {
21942218 let ty = resolve ! ( ctx, expr) ;
2195- let gctx = & ctx. module . to_ctx ( ) ;
21962219 return Err ( Box :: new ( Error :: BadTypeCast {
2197- from_type : ty . to_wgsl ( gctx ) ,
2220+ from_type : ctx . type_resolution_to_string ( ty ) ,
21982221 span : ty_span,
2199- to_type : to_resolved . to_wgsl ( gctx ) ,
2222+ to_type : ctx . type_to_string ( to_resolved ) ,
22002223 } ) ) ;
22012224 }
22022225 } ;
0 commit comments