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