Skip to content

Commit

Permalink
glsl-in: Update initializer list type when parsing
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JCapucho committed Sep 18, 2022
1 parent 1a99c1c commit e442553
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/front/glsl/parser/declarations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e442553

Please sign in to comment.