diff --git a/naga/src/front/wgsl/lower/mod.rs b/naga/src/front/wgsl/lower/mod.rs index f568cf34b3..238d8f67c2 100644 --- a/naga/src/front/wgsl/lower/mod.rs +++ b/naga/src/front/wgsl/lower/mod.rs @@ -237,6 +237,7 @@ impl<'a, 'temp> StatementContext<'a, 'temp, '_> { } } + #[allow(dead_code)] fn as_global(&mut self) -> GlobalContext<'a, '_, '_> { GlobalContext { ast_expressions: self.ast_expressions, @@ -1617,7 +1618,6 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let uint = resolve_inner!(ectx, selector).scalar_kind() == Some(crate::ScalarKind::Uint); - block.extend(emitter.finish(&ctx.function.expressions)); let cases = cases .iter() @@ -1626,8 +1626,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { value: match case.value { ast::SwitchValue::Expr(expr) => { let span = ctx.ast_expressions.get_span(expr); - let expr = - self.expression(expr, &mut ctx.as_global().as_const())?; + let expr = self + .expression(expr, &mut ctx.as_const(block, &mut emitter))?; match ctx.module.to_ctx().eval_expr_to_literal(expr) { Some(crate::Literal::I32(value)) if !uint => { crate::SwitchValue::I32(value) @@ -1648,6 +1648,8 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { }) .collect::>()?; + block.extend(emitter.finish(&ctx.function.expressions)); + crate::Statement::Switch { selector, cases } } ast::StatementKind::Loop { @@ -2936,7 +2938,7 @@ impl<'source, 'temp> Lowerer<'source, 'temp> { let offset = args .next() - .map(|arg| self.expression(arg, &mut ctx.as_global().as_const())) + .map(|arg| self.expression(arg, &mut ctx.as_const())) .ok() .transpose()?;