Skip to content

Commit 65c2efb

Browse files
GearsDatapackslpil
authored andcommitted
Fix crash
1 parent 4209ab0 commit 65c2efb

File tree

4 files changed

+43
-2
lines changed

4 files changed

+43
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
### Bug Fixes
1414

15+
- Fixed a bug which caused the language server and compiler to crash when
16+
two constructors of the same name were created.
17+
([Surya Rose](https://github.com/GearsDatapacks))
18+
1519
## v1.4.1 - 2024-08-04
1620

1721
### Bug Fixes

compiler-core/src/analyse.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -867,11 +867,14 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
867867
let mut constructors_data = vec![];
868868

869869
for (index, constructor) in constructors.iter().enumerate() {
870-
assert_unique_name(
870+
if let Err(error) = assert_unique_name(
871871
&mut self.value_names,
872872
&constructor.name,
873873
constructor.location,
874-
)?;
874+
) {
875+
self.problems.error(error);
876+
continue;
877+
}
875878

876879
let mut field_map = FieldMap::new(constructor.arguments.len() as u32);
877880
let mut args_types = Vec::with_capacity(constructor.arguments.len());

compiler-core/src/type_/tests/errors.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2172,3 +2172,23 @@ pub fn main() {
21722172
"
21732173
);
21742174
}
2175+
2176+
#[test]
2177+
fn no_crash_on_duplicate_definition() {
2178+
// This previous caused the compiler to crash
2179+
assert_module_error!(
2180+
"
2181+
type Wibble {
2182+
Wobble
2183+
Wobble
2184+
}
2185+
2186+
pub fn main() {
2187+
let wibble = Wobble
2188+
case wibble {
2189+
Wobble -> Nil
2190+
}
2191+
}
2192+
"
2193+
);
2194+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
source: compiler-core/src/type_/tests/errors.rs
3+
expression: "\ntype Wibble {\n Wobble\n Wobble\n}\n\npub fn main() {\n let wibble = Wobble\n case wibble {\n Wobble -> Nil\n }\n}\n"
4+
---
5+
error: Duplicate definition
6+
┌─ /src/one/two.gleam:3:3
7+
8+
3Wobble
9+
^^^^^^ First defined here
10+
4Wobble
11+
^^^^^^ Redefined here
12+
13+
`Wobble` has been defined multiple times.
14+
Names in a Gleam module must be unique so one will need to be renamed.

0 commit comments

Comments
 (0)