swamp_script_error_report/
semantic.rs

1use crate::{Builder, Report, build_and_print};
2use eira::Kind;
3use std::path::Path;
4use swamp_script_node::Span;
5use swamp_script_semantic::SemanticError;
6use swamp_script_source_map::SourceMap;
7
8#[must_use]
9pub fn build_semantic_error(err: &SemanticError, span: &Span) -> Builder<usize> {
10    let mut b = match err {
11        SemanticError::CouldNotInsertStruct => {
12            Report::build(Kind::Error, 140, "CouldNotInsertStruct", span)
13        }
14        SemanticError::DuplicateTypeAlias(_) => {
15            Report::build(Kind::Error, 140, "DuplicateTypeAlias", span)
16        }
17        SemanticError::CanOnlyUseStructForMemberFunctions => {
18            Report::build(Kind::Error, 140, "CanOnlyUseStructForMemberFunctions", span)
19        }
20        SemanticError::ResolveNotStruct => {
21            Report::build(Kind::Error, 140, "ResolveNotStruct", span)
22        }
23        SemanticError::DuplicateStructName(_) => {
24            Report::build(Kind::Error, 140, "DuplicateStructName", span)
25        }
26        SemanticError::DuplicateEnumType(_) => {
27            Report::build(Kind::Error, 140, "DuplicateEnumType", span)
28        }
29        SemanticError::DuplicateEnumVariantType(_, _) => {
30            Report::build(Kind::Error, 140, "DuplicateEnumVariantType", span)
31        }
32        SemanticError::DuplicateFieldName(_) => {
33            Report::build(Kind::Error, 140, "DuplicateFieldName", span)
34        }
35        SemanticError::DuplicateExternalFunction(_) => {
36            Report::build(Kind::Error, 140, "DuplicateExternalFunction", span)
37        }
38        SemanticError::DuplicateRustType(_) => {
39            Report::build(Kind::Error, 140, "DuplicateRustType", span)
40        }
41        SemanticError::DuplicateConstName(_) => {
42            Report::build(Kind::Error, 140, "DuplicateConstName", span)
43        }
44        SemanticError::CircularConstantDependency(_) => {
45            Report::build(Kind::Error, 140, "CircularConstantDependency", span)
46        }
47        SemanticError::DuplicateConstantId(_) => {
48            Report::build(Kind::Error, 140, "DuplicateConstantId", span)
49        }
50        SemanticError::IncompatibleTypes => {
51            Report::build(Kind::Error, 140, "IncompatibleTypes", span)
52        }
53        SemanticError::WasNotImmutable => Report::build(Kind::Error, 140, "WasNotImmutable", span),
54        SemanticError::WasNotMutable => Report::build(Kind::Error, 140, "WasNotMutable", span),
55        SemanticError::UnknownImplOnType => {
56            Report::build(Kind::Error, 140, "UnknownImplOnType", span)
57        }
58        SemanticError::DuplicateNamespaceLink(_) => {
59            Report::build(Kind::Error, 140, "DuplicateNamespaceLink", span)
60        }
61        SemanticError::DuplicateSymbolName(_) => {
62            Report::build(Kind::Error, 140, "duplicate symbol", span)
63        }
64        SemanticError::MismatchedTypes { .. } => {
65            Report::build(Kind::Error, 140, "mismatch types", span)
66        }
67        SemanticError::UnknownTypeVariable => {
68            Report::build(Kind::Error, 140, "unknown type variable", span)
69        }
70    };
71
72    b.error_module = "S".to_string();
73    b
74}
75
76pub fn show_semantic_error(err: &SemanticError, source_map: &SourceMap, current_dir: &Path) {
77    let builder = build_semantic_error(err, &Span::default());
78    build_and_print(builder, source_map, current_dir);
79}