Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 3108 #3226

Merged
merged 12 commits into from
Jun 22, 2024
19 changes: 14 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@

([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- The syntax `[a..b]` is now deprecated in favour of the `[a, ..b]` syntax.
This was to avoid it being mistaken for a range syntax, which Gleam does
not have.
([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- Functions etc named `maybe` are now escaped in generated Erlang as it is now a
reserved word in Erlang/OTP 27.
([Jake Barszcz](https://github.com/barszcz))
Expand All @@ -59,7 +64,8 @@
Unsupported feature for Javascript since they would already cause
a runtime error on Javascript.

This means if you compile specifically for Javascript you will now recieve this error:
This means if you compile specifically for Javascript you will now recieve
this error:

```
error: Unsupported feature for compilation target
Expand All @@ -72,6 +78,7 @@
```

Else any functions which rely on this will not be compiled into Javascript.
([Pi-Cla](https://github.com/Pi-Cla))

- Compilation fault tolerance is now at a statement level instead of a function
level. This means that the compiler will attempt to infer the rest of the
Expand Down Expand Up @@ -103,11 +110,13 @@

([Giacomo Cavalieri](https://github.com/giacomocavalieri))

- LSP can now suggest completions for values and types from importable modules and adds the import to the top of the file.
([Ameen Radwan](https://github.com/Acepie))
- LSP can now suggest completions for values and types from importable modules
and adds the import to the top of the file.
([Ameen Radwan](https://github.com/Acepie)

- LSP completions now use the "text_edit" language server API resulting in better/more accurate insertions.
([Ameen Radwan](https://github.com/Acepie))
- LSP completions now use the "text_edit" language server API resulting in
better/more accurate insertions.
([Ameen Radwan](https://github.com/Acepie)

### Bug Fixes

Expand Down
2 changes: 2 additions & 0 deletions compiler-core/src/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ impl UntypedModule {
#[test]
fn module_dependencies_test() {
let parsed = crate::parse::parse_module(
camino::Utf8PathBuf::from("test/path"),
"import one
@target(erlang)
import two
Expand All @@ -116,6 +117,7 @@ fn module_dependencies_test() {
import three

import four",
&crate::warning::WarningEmitter::null(),
)
.expect("syntax error");
let module = parsed.module;
Expand Down
7 changes: 6 additions & 1 deletion compiler-core/src/ast/tests.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use std::sync::Arc;

use camino::Utf8PathBuf;

use crate::analyse::TargetSupport;
use crate::build::Target;
use crate::config::PackageConfig;
use crate::line_numbers::LineNumbers;
use crate::type_::expression::FunctionDefinition;
use crate::type_::{Deprecation, PRELUDE_MODULE_NAME};
use crate::warning::WarningEmitter;
use crate::{
ast::{SrcSpan, TypedExpr},
build::Located,
Expand All @@ -21,7 +24,9 @@ use super::{Publicity, Statement, TypedModule, TypedStatement};

fn compile_module(src: &str) -> TypedModule {
use crate::type_::build_prelude;
let parsed = crate::parse::parse_module(src).expect("syntax error");
let parsed =
crate::parse::parse_module(Utf8PathBuf::from("test/path"), src, &WarningEmitter::null())
.expect("syntax error");
let ast = parsed.module;
let ids = UniqueIdGenerator::new();
let mut config = PackageConfig::default();
Expand Down
14 changes: 9 additions & 5 deletions compiler-core/src/build/module_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use super::{
use crate::{
error::{FileIoAction, FileKind},
io::{CommandExecutor, FileSystemReader, FileSystemWriter},
warning::WarningEmitter,
warning::{TypeWarningEmitter, WarningEmitter},
Error, Result,
};

Expand Down Expand Up @@ -125,6 +125,7 @@ where
name,
self.package_name.clone(),
mtime,
self.warnings.clone(),
)
}

Expand All @@ -147,16 +148,19 @@ pub(crate) fn read_source<IO>(
name: EcoString,
package_name: EcoString,
mtime: SystemTime,
emitter: WarningEmitter,
) -> Result<UncompiledModule>
where
IO: FileSystemReader + FileSystemWriter + CommandExecutor + Clone,
{
let code: EcoString = io.read(&path)?.into();

let parsed = crate::parse::parse_module(&code).map_err(|error| Error::Parse {
path: path.clone(),
src: code.clone(),
error,
let parsed = crate::parse::parse_module(path.clone(), &code, &emitter).map_err(|error| {
Error::Parse {
path: path.clone(),
src: code.clone(),
error,
}
})?;
let mut ast = parsed.module;
let extra = parsed.extra;
Expand Down
1 change: 1 addition & 0 deletions compiler-core/src/build/package_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ where
cached.name,
self.package_name.clone(),
mtime,
self.warnings.clone(),
)
}
}
Expand Down
14 changes: 12 additions & 2 deletions compiler-core/src/erlang/tests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use camino::Utf8PathBuf;

use crate::analyse::TargetSupport;
use crate::config::PackageConfig;
use crate::type_::PRELUDE_MODULE_NAME;
use crate::warning::WarningEmitter;
use crate::{
build::{Origin, Target},
erlang::module,
Expand Down Expand Up @@ -44,7 +47,12 @@ pub fn compile_test_project(src: &str, dep: Option<(&str, &str, &str)>) -> Strin
if let Some((dep_package, dep_name, dep_src)) = dep {
let mut dep_config = PackageConfig::default();
dep_config.name = dep_package.into();
let parsed = crate::parse::parse_module(dep_src).expect("dep syntax error");
let parsed = crate::parse::parse_module(
Utf8PathBuf::from("test/path"),
dep_src,
&WarningEmitter::null(),
)
.expect("dep syntax error");
let mut ast = parsed.module;
ast.name = dep_name.into();
let line_numbers = LineNumbers::new(dep_src);
Expand All @@ -64,7 +72,9 @@ pub fn compile_test_project(src: &str, dep: Option<(&str, &str, &str)>) -> Strin
let _ = modules.insert(dep_name.into(), dep.type_info);
let _ = direct_dependencies.insert(dep_package.into(), ());
}
let parsed = crate::parse::parse_module(src).expect("syntax error");
let parsed =
crate::parse::parse_module(Utf8PathBuf::from("test/path"), src, &WarningEmitter::null())
.expect("syntax error");
let mut config = PackageConfig::default();
config.name = "thepackage".into();
let mut ast = parsed.module;
Expand Down
12 changes: 7 additions & 5 deletions compiler-core/src/fix.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
use crate::{
format::{Formatter, Intermediate},
warning::WarningEmitter,
Error, Result,
};
use camino::Utf8Path;
use ecow::EcoString;

pub fn parse_fix_and_format(src: &EcoString, path: &Utf8Path) -> Result<String> {
// Parse
let parsed = crate::parse::parse_module(src).map_err(|error| Error::Parse {
path: path.to_path_buf(),
src: src.clone(),
error,
})?;
let parsed = crate::parse::parse_module(path.to_owned(), src, &WarningEmitter::null())
.map_err(|error| Error::Parse {
path: path.to_path_buf(),
src: src.clone(),
error,
})?;
let intermediate = Intermediate::from_extra(&parsed.extra, src);
let module = parsed.module;

Expand Down
12 changes: 7 additions & 5 deletions compiler-core/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use crate::{
parse::extra::{Comment, ModuleExtra},
pretty::{self, *},
type_::{self, Type},
warning::WarningEmitter,
Error, Result,
};
use ecow::EcoString;
Expand All @@ -25,11 +26,12 @@ use camino::Utf8Path;
const INDENT: isize = 2;

pub fn pretty(writer: &mut impl Utf8Writer, src: &EcoString, path: &Utf8Path) -> Result<()> {
let parsed = crate::parse::parse_module(src).map_err(|error| Error::Parse {
path: path.to_path_buf(),
src: src.clone(),
error,
})?;
let parsed = crate::parse::parse_module(path.to_owned(), src, &WarningEmitter::null())
.map_err(|error| Error::Parse {
path: path.to_path_buf(),
src: src.clone(),
error,
})?;
let intermediate = Intermediate::from_extra(&parsed.extra, src);
Formatter::with_comments(&intermediate)
.module(&parsed.module)
Expand Down
15 changes: 11 additions & 4 deletions compiler-core/src/javascript/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ use crate::{
config::PackageConfig,
javascript::*,
uid::UniqueIdGenerator,
warning::TypeWarningEmitter,
warning::{TypeWarningEmitter, WarningEmitter},
};
use camino::Utf8Path;
use camino::{Utf8Path, Utf8PathBuf};

mod assignments;
mod bit_arrays;
Expand Down Expand Up @@ -98,7 +98,12 @@ pub fn compile(src: &str, deps: Vec<(&str, &str, &str)>) -> TypedModule {
deps.iter().for_each(|(dep_package, dep_name, dep_src)| {
let mut dep_config = PackageConfig::default();
dep_config.name = (*dep_package).into();
let parsed = crate::parse::parse_module(dep_src).expect("dep syntax error");
let parsed = crate::parse::parse_module(
Utf8PathBuf::from("test/path"),
dep_src,
&WarningEmitter::null(),
)
.expect("dep syntax error");
let mut ast = parsed.module;
ast.name = (*dep_name).into();
let line_numbers = LineNumbers::new(dep_src);
Expand All @@ -119,7 +124,9 @@ pub fn compile(src: &str, deps: Vec<(&str, &str, &str)>) -> TypedModule {
let _ = direct_dependencies.insert((*dep_package).into(), ());
});

let parsed = crate::parse::parse_module(src).expect("syntax error");
let parsed =
crate::parse::parse_module(Utf8PathBuf::from("test/path"), src, &WarningEmitter::null())
.expect("syntax error");
let mut ast = parsed.module;
ast.name = "my/mod".into();
let line_numbers = LineNumbers::new(src);
Expand Down
14 changes: 11 additions & 3 deletions compiler-core/src/package_interface/tests.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::time::SystemTime;

use camino::Utf8PathBuf;
use ecow::EcoString;
use globset::GlobBuilder;
use hexpm::version::Identifier;
Expand All @@ -11,7 +12,7 @@ use crate::{
line_numbers::LineNumbers,
type_::PRELUDE_MODULE_NAME,
uid::UniqueIdGenerator,
warning::TypeWarningEmitter,
warning::{TypeWarningEmitter, WarningEmitter},
};

use super::PackageInterface;
Expand Down Expand Up @@ -68,7 +69,12 @@ pub fn compile_package(
);
let mut direct_dependencies = std::collections::HashMap::from_iter(vec![]);
if let Some((dep_package, dep_name, dep_src)) = dep {
let parsed = crate::parse::parse_module(dep_src).expect("dep syntax error");
let parsed = crate::parse::parse_module(
Utf8PathBuf::from("test/path"),
dep_src,
&WarningEmitter::null(),
)
.expect("dep syntax error");
let mut ast = parsed.module;
ast.name = dep_name.into();
let line_numbers = LineNumbers::new(dep_src);
Expand All @@ -90,7 +96,9 @@ pub fn compile_package(
let _ = modules.insert(dep_name.into(), dep.type_info);
let _ = direct_dependencies.insert(dep_package.into(), ());
}
let parsed = crate::parse::parse_module(src).expect("syntax error");
let parsed =
crate::parse::parse_module(Utf8PathBuf::from("test/path"), src, &WarningEmitter::null())
.expect("syntax error");

let mut ast = parsed.module;
let module_name = module_name
Expand Down
Loading
Loading