Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasavila00 committed Dec 14, 2024
1 parent a399d7d commit 92189f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/beff-core/src/diag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::{BffFileName, ParsedModule};

#[derive(Debug, Clone)]
pub enum DiagnosticInfoMessage {
ObjectHasConflictingKeyValueInIntersection,
CannotResolveNamedImport,
EnumMemberNotFound,
TplLitTypeUnsupported,
Expand Down Expand Up @@ -461,6 +462,9 @@ impl DiagnosticInfoMessage {
DiagnosticInfoMessage::CannotResolveNamedImport => {
"Cannot resolve named import".to_string()
}
DiagnosticInfoMessage::ObjectHasConflictingKeyValueInIntersection => {
"Object has conflicting key value in intersection".to_string()
}
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion packages/beff-core/src/type_to_schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,26 @@ impl<'a, 'b, R: FileManager> TypeToSchema<'a, 'b, R> {
let map = self.components.get(r).and_then(|it| it.as_ref()).cloned();
match map {
Some(Validator { schema, .. }) => self.extract_object(&schema, span),
_ => self.error(span, DiagnosticInfoMessage::ShouldHaveObjectAsTypeArgument),
None => self.error(span, DiagnosticInfoMessage::ShouldHaveObjectAsTypeArgument),
}
}
JsonSchema::AllOf(vs) => {
let mut acc = BTreeMap::new();

for v in vs {
let extracted = self.extract_object(v, span)?;

// check that if items have the same key, they have the same value

for (k, v) in &extracted {
if let Some(existing) = acc.get(k) {
if existing != v {
return self
.error(span, DiagnosticInfoMessage::ObjectHasConflictingKeyValueInIntersection);
}
}
}

acc.extend(extracted);
}

Expand Down

0 comments on commit 92189f7

Please sign in to comment.