Skip to content

Commit

Permalink
Permanently enable type checker
Browse files Browse the repository at this point in the history
This now works for everything that we can transpile and run
successfully. So let's turn it on for good.
  • Loading branch information
emk committed Nov 6, 2023
1 parent 6c4dfbe commit d3aceae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
16 changes: 4 additions & 12 deletions src/cmd/sql_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ pub struct SqlTestOpt {
/// Run pending tests.
#[clap(long)]
pending: bool,

/// Run the type checker on each test (this will eventually become
/// automatic).
#[clap(long)]
type_check: bool,
}

/// Run our SQL test suite.
Expand Down Expand Up @@ -93,7 +88,7 @@ pub async fn cmd_sql_test(files: &mut KnownFiles, opt: &SqlTestOpt) -> Result<()

// Test query.
let mut driver = locator.driver().await?;
match run_test(&mut *driver, files, file_id, opt.type_check).await {
match run_test(&mut *driver, files, file_id).await {
Ok(_) => {
progress('.');
test_ok_count += 1;
Expand Down Expand Up @@ -149,15 +144,12 @@ async fn run_test(
driver: &mut dyn Driver,
files: &mut KnownFiles,
file_id: FileId,
type_check: bool,
) -> std::result::Result<(), Error> {
let mut ast = parse_sql(files, file_id)?;

// Optionally type check the AST.
if type_check {
let scope = Scope::root();
ast.infer_types(&scope)?;
}
// Type check the AST.
let scope = Scope::root();
ast.infer_types(&scope)?;

//eprintln!("SQLite3: {}", ast.emit_to_string(Target::SQLite3));
let output_tables = find_output_tables(&ast)?;
Expand Down
13 changes: 12 additions & 1 deletion src/cmd/transpile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use crate::{
ast::{parse_sql, Emit},
drivers,
errors::Result,
infer::InferTypes,
known_files::KnownFiles,
scope::Scope,
};

/// Run SQL tests from a directory.
Expand All @@ -33,7 +35,16 @@ pub async fn cmd_transpile(files: &mut KnownFiles, opt: &TranspileOpt) -> Result

// Parse our SQL.
let file_id = files.add(&opt.sql_path)?;
let ast = parse_sql(files, file_id)?;
let mut ast = parse_sql(files, file_id)?;

// Run the type checker, but do not fail on errors.
let scope = Scope::root();
if let Err(err) = ast.infer_types(&scope) {
err.emit(files);
eprintln!("\nType checking failed. Manual fixes will probably be required!");
}

// Rewrite our AST.
let rewritten_ast = driver.rewrite_ast(&ast)?;

// Print our rewritten AST.
Expand Down

0 comments on commit d3aceae

Please sign in to comment.