This repository was archived by the owner on Jan 29, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -33,6 +33,8 @@ pub enum GlobalVariableError {
3333 ) ,
3434 #[ error( "Initializer doesn't match the variable type" ) ]
3535 InitializerType ,
36+ #[ error( "Initializer can't be used with address space {0:?}" ) ]
37+ InitializerNotAllowed ( crate :: AddressSpace ) ,
3638 #[ error( "Storage address space doesn't support write-only access" ) ]
3739 StorageAddressSpaceWriteOnlyNotSupported ,
3840}
@@ -572,6 +574,13 @@ impl super::Validator {
572574 }
573575
574576 if let Some ( init) = var. init {
577+ match var. space {
578+ crate :: AddressSpace :: Private | crate :: AddressSpace :: Function => { }
579+ _ => {
580+ return Err ( GlobalVariableError :: InitializerNotAllowed ( var. space ) ) ;
581+ }
582+ }
583+
575584 let decl_ty = & gctx. types [ var. ty ] . inner ;
576585 let init_ty = mod_info[ init] . inner_with ( gctx. types ) ;
577586 if !decl_ty. equivalent ( init_ty, gctx. types ) {
Original file line number Diff line number Diff line change @@ -1606,6 +1606,21 @@ fn host_shareable_types() {
16061606 }
16071607}
16081608
1609+ #[ test]
1610+ fn var_init ( ) {
1611+ check_validation ! {
1612+ "
1613+ var<workgroup> initialized: u32 = 0u;
1614+ " :
1615+ Err (
1616+ naga:: valid:: ValidationError :: GlobalVariable {
1617+ source: naga:: valid:: GlobalVariableError :: InitializerNotAllowed ( naga:: AddressSpace :: WorkGroup ) ,
1618+ ..
1619+ } ,
1620+ )
1621+ }
1622+ }
1623+
16091624#[ test]
16101625fn misplaced_break_if ( ) {
16111626 check (
You can’t perform that action at this time.
0 commit comments