1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/// given `assertType` calls, displays the result
pub struct AssertTypeExplainer;

// impl Visitor<parser::Expression, TypeMappings> for AssertTypeExplainer {
// 	fn visit(
// 		&mut self,
// 		item: &parser::Expression,
// 		data: &mut TypeMappings,
// 		_chain: &parser::Chain,
// 	) {
// 		if let parser::Expression::FunctionCall { function, arguments, .. } = item {
// 			let ty = data
// 				.type_mappings
// 				.get_instance_for_expression(&function.get_expression_id().unwrap())
// 				.unwrap()
// 				.get_type();

// 			let function_calls = data.environment.get_constant_type(ty);

// 			if let Some(this_function_constant) = function_calls {
// 				let assert_type_function_constant: Constant =
// 					crate::InternalFunctionId::ASSERT_TYPE.into();
// 				let print_effects_function_constant: Constant =
// 					crate::InternalFunctionId::PRINT_EFFECTS.into();

// 				if this_function_constant == &assert_type_function_constant {
// 					print_arguments(arguments, data);
// 				} else if this_function_constant == &print_effects_function_constant {
// 					print_effects(arguments, data);
// 				}
// 			} else {
// 				eprintln!(
// 					"Calling thingy, maybe should have been replaced {:?}",
// 					data.environment.get_type_by_id(ty)
// 				);
// 			}
// 		}
// 	}
// }

// fn print_arguments(
// 	arguments: &Vec<parser::expressions::SpreadExpression>,
// 	data: &mut crate::AnalysisPassDataGroup,
// ) {
// 	let argument =
// 		if let Some(parser::expressions::SpreadExpression::NonSpread(expr)) = &arguments.first() {
// 			expr
// 		} else {
// 			unreachable!("type checking failed")
// 		};

// 	let instance =
// 		data.type_mappings.get_instance_for_expression(&argument.get_expression_id().unwrap());
// 	let diagnostic = if let Some(instance) = instance {
// 		let type_id = instance.get_type();
// 		let ty = data.environment.get_type_by_id(type_id);
// 		let mut value_as_string =
// 			TypeDisplay::to_string(&type_id, &data.environment.into_general_context());

// 		let specializations = data.environment.specializations.get(&type_id);
// 		if let Some(specializations) = specializations {
// 			value_as_string.push_str(" specialized with ");
// 			for specialization in specializations.iter().copied() {
// 				let ty = data.environment.get_type_by_id(specialization);
// 				let specializations_as_string = TypeDisplay::to_string(
// 					&specialization,
// 					&data.environment.into_general_context(),
// 				);

// 				value_as_string.push_str(&specializations_as_string);
// 				value_as_string.push_str(", ");
// 			}
// 		}

// 		if let Some(Constant::FunctionReference(function_pointer)) =
// 			data.environment.get_constant_type(type_id)
// 		{
// 			crate::utils::notify!("TODO function references");
// 			Diagnostic::PositionWithAdditionLabels {
// 				labels: data
// 					.type_mappings
// 					.functions_to_positions
// 					.get(&function_pointer)
// 					.map(|span| (format!("Found function"), Some(span.clone())))
// 					.into_iter()
// 					.collect(),
// 				reason: format!("assertion passed with: {}", value_as_string),
// 				pos: argument.get_position().into_owned(),
// 			}
// 		} else {
// 			Diagnostic::Position {
// 				reason: format!("assertion passed with: {}", value_as_string),
// 				pos: argument.get_position().into_owned(),
// 			}
// 		}
// 	} else {
// 		Diagnostic::Position {
// 			reason: format!("assertion passed, however no type mapping present"),
// 			pos: argument.get_position().into_owned(),
// 		}
// 	};
// 	data.error_handler.add_info(diagnostic);
// }

// fn print_effects(
// 	arguments: &Vec<parser::expressions::SpreadExpression>,
// 	data: &mut crate::AnalysisPassDataGroup,
// ) {
// 	let argument =
// 		if let Some(parser::expressions::SpreadExpression::NonSpread(expr)) = &arguments.first() {
// 			expr
// 		} else {
// 			unreachable!("type checking failed")
// 		};

// 	let instance =
// 		data.type_mappings.get_instance_for_expression(&argument.get_expression_id().unwrap());
// 	let diagnostic = if let Some(instance) = instance {
// 		let type_id = instance.get_type();

// 		let specializations = data.environment.specializations.get(&type_id);
// 		if let Some(_specializations) = specializations {
// 			todo!()
// 		// value_as_string.push_str(" specialized with ");
// 		// for specialization in specializations.iter().copied() {
// 		// 	let ty = data.environment.get_type_by_id(specialization);
// 		// 	let specializations_as_string = (specialization, ty)
// 		// 		.to_string(&data.environment.into_general_context());

// 		// 	value_as_string.push_str(&specializations_as_string);
// 		// 	value_as_string.push_str(", ");
// 		// }
// 		} else if let Some(function) = data.environment.get_function(type_id) {
// 			// TODO prettier result that verbose debug
// 			Diagnostic::Position {
// 				reason: format!("effects on function: {:#?}", function.effects),
// 				pos: argument.get_position().into_owned(),
// 			}
// 		} else {
// 			Diagnostic::Position {
// 				reason: "not a function wtf".into(),
// 				pos: argument.get_position().into_owned(),
// 			}
// 		}
// 	} else {
// 		unreachable!()
// 	};
// 	data.error_handler.add_info(diagnostic);
// }