Skip to content

Commit 934e794

Browse files
authored
Merge pull request #2053 from Smit-create/i-2044
Throw error instead of exception
2 parents 77385b9 + 284958f commit 934e794

File tree

5 files changed

+40
-2
lines changed

5 files changed

+40
-2
lines changed

src/libasr/codegen/asr_to_llvm.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7387,8 +7387,8 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
73877387
fmt.push_back("%d");
73887388
args.push_back(tmp);
73897389
} else {
7390-
throw LCompilersException("Printing support is not available for " +
7391-
ASRUtils::type_to_str(t) + " type.");
7390+
throw CodeGenError("Printing support is not available for `" +
7391+
ASRUtils::type_to_str(t) + "` type.", x.base.base.loc);
73927392
}
73937393
}
73947394
fmt.push_back("%s");

tests/errors/structs_11.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from lpython import dataclass, i32
2+
3+
# test issue 2044
4+
5+
@dataclass
6+
class Foo:
7+
x : i32
8+
9+
@dataclass
10+
class Bar:
11+
foo : Foo = Foo()
12+
13+
bar : Bar = Bar()
14+
15+
print(bar.foo)
16+
print(bar)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"basename": "llvm-structs_11-a746e1b",
3+
"cmd": "lpython --no-color --show-llvm {infile} -o {outfile}",
4+
"infile": "tests/errors/structs_11.py",
5+
"infile_hash": "9cb6c80ad837ba66472a91b22e9068ec439b6a2a179a452d90d84c78",
6+
"outfile": null,
7+
"outfile_hash": null,
8+
"stdout": null,
9+
"stdout_hash": null,
10+
"stderr": "llvm-structs_11-a746e1b.stderr",
11+
"stderr_hash": "58e383d2ac915263088426f1b511760a8cb9ef3dd6f24cb207eda4de",
12+
"returncode": 3
13+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
code generation error: Printing support is not available for `Foo` type.
2+
--> tests/errors/structs_11.py:16:1
3+
|
4+
16 | print(bar)
5+
| ^^^^^^^^^^

tests/tests.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,10 @@ asr = true
687687
filename = "errors/structs_10.py"
688688
asr = true
689689

690+
[[test]]
691+
filename = "errors/structs_11.py"
692+
llvm = true
693+
690694
[[test]]
691695
filename = "errors/const_01.py"
692696
asr = true

0 commit comments

Comments
 (0)