From 5689128262af6d044c81b3b3ce425b131b5bc91a Mon Sep 17 00:00:00 2001 From: Raymond Zhang Date: Tue, 17 Dec 2024 11:11:06 -0500 Subject: [PATCH] Add invalid alias test case. --- sema/import_test.go | 46 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/sema/import_test.go b/sema/import_test.go index a9a71d715..b424e2cfb 100644 --- a/sema/import_test.go +++ b/sema/import_test.go @@ -877,7 +877,7 @@ func TestCheckImportAlias(t *testing.T) { require.NoError(t, err) }) - t.Run("valid, multiple alias of same contract", func(t *testing.T) { + t.Run("valid multiple alias of same contract", func(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` @@ -926,7 +926,7 @@ func TestCheckImportAlias(t *testing.T) { require.NoError(t, err) }) - t.Run("invalid, duplicate aliases", func(t *testing.T) { + t.Run("invalid duplicate aliases", func(t *testing.T) { importedChecker, err := ParseAndCheckWithOptions(t, ` @@ -1015,4 +1015,46 @@ func TestCheckImportAlias(t *testing.T) { }) + t.Run("invalid use orig instead of alias", func(t *testing.T) { + + importedChecker, err := ParseAndCheckWithOptions(t, + ` + access(all) fun a(): Int { + return 42 + } + + `, + ParseAndCheckOptions{ + Location: ImportedLocation, + }, + ) + + require.NoError(t, err) + + _, err = ParseAndCheckWithOptions(t, + ` + import a as b from "imported" + + access(all) fun main() { + a() + } + `, + ParseAndCheckOptions{ + Config: &sema.Config{ + ImportHandler: func(_ *sema.Checker, _ common.Location, _ ast.Range) (sema.Import, error) { + return sema.ElaborationImport{ + Elaboration: importedChecker.Elaboration, + }, nil + }, + }, + }, + ) + + errs := RequireCheckerErrors(t, err, 1) + + notDeclaredError := &sema.NotDeclaredError{} + assert.ErrorAs(t, errs[0], ¬DeclaredError) + + }) + }