From e442553da3bc89404224dd63a444753eadbb18fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Capucho?= Date: Sun, 18 Sep 2022 13:01:56 +0100 Subject: [PATCH] glsl-in: Update initializer list type when parsing Previously when parsing an initializer list, the type passed to `parse_initializer` was not updated to reflect the child type, this caused implicit conversions to not work and nested initializer lists to not be allowed. --- src/front/glsl/parser/declarations.rs | 31 +++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/front/glsl/parser/declarations.rs b/src/front/glsl/parser/declarations.rs index 346d20b19e..bdcb4a2b80 100644 --- a/src/front/glsl/parser/declarations.rs +++ b/src/front/glsl/parser/declarations.rs @@ -68,8 +68,35 @@ impl<'source> ParsingContext<'source> { // initializer_list let mut components = Vec::new(); loop { - // TODO: Change type - components.push(self.parse_initializer(parser, ty, ctx, body)?.0); + // The type expected to be parsed inside the initializer list + let new_ty = match parser.module.types[ty].inner { + TypeInner::Vector { kind, width, .. } => parser.module.types.insert( + Type { + name: None, + inner: TypeInner::Scalar { kind, width }, + }, + Default::default(), + ), + TypeInner::Matrix { rows, width, .. } => parser.module.types.insert( + Type { + name: None, + inner: TypeInner::Vector { + size: rows, + kind: ScalarKind::Float, + width, + }, + }, + Default::default(), + ), + TypeInner::Array { base, .. } => base, + TypeInner::Struct { ref members, .. } => members + .get(components.len()) + .map(|member| member.ty) + .unwrap_or(ty), + _ => ty, + }; + + components.push(self.parse_initializer(parser, new_ty, ctx, body)?.0); let token = self.bump(parser)?; match token.value {