@@ -11,8 +11,9 @@ import { Expr } from "./Expr.js"
1111import { PathExpr } from "./PathExpr.js"
1212
1313/**
14- * @typedef {import("@helios-lang/compiler-utils").Site } Site
15- * @typedef {import("@helios-lang/ir").SourceMappedStringI } SourceMappedStringI
14+ * @import { Site } from "@helios-lang/compiler-utils"
15+ * @import { SourceMappedStringI } from "@helios-lang/ir"
16+ * @import { TypeCheckContext } from "../index.js"
1617 * @typedef {import("../typecheck/index.js").EvalEntity } EvalEntity
1718 */
1819
@@ -47,24 +48,26 @@ export class AssignExpr extends ChainExpr {
4748 }
4849
4950 /**
51+ * @param {TypeCheckContext } ctx
5052 * @param {Scope } scope
5153 * @returns {EvalEntity }
5254 */
53- evalInternal ( scope ) {
55+ evalInternal ( ctx , scope ) {
5456 const subScope = new Scope ( scope , scope . allowShadowing )
5557
56- let upstreamVal = this . upstreamExpr . eval ( scope )
58+ let upstreamVal = this . upstreamExpr . eval ( ctx , scope )
5759
5860 if ( upstreamVal && upstreamVal . asTyped ) {
5961 if ( new VoidType ( ) . isBaseOf ( upstreamVal . asTyped . type ) ) {
60- throw makeTypeError (
62+ ctx . errors . type (
6163 this . upstreamExpr . site ,
6264 "can't assign to unit type"
6365 )
6466 }
6567
6668 if ( this . _nameType . hasType ( ) || this . _nameType . isTuple ( ) ) {
6769 this . _nameType . evalInAssignExpr (
70+ ctx ,
6871 subScope ,
6972 expectDefined ( upstreamVal . asTyped . type . asType ) ,
7073 0
@@ -90,13 +93,14 @@ export class AssignExpr extends ChainExpr {
9093 }
9194 } else if ( this . _nameType . hasType ( ) ) {
9295 // this is the fallback case if the upstream has itself a typeerror
93- this . _nameType . evalInAssignExpr ( subScope , undefined , 0 )
96+ this . _nameType . evalInAssignExpr ( ctx , subScope , undefined , 0 )
9497 } else {
95- throw makeTypeError ( this . upstreamExpr . site , "rhs isn't an instance" )
98+ ctx . errors . type ( this . upstreamExpr . site , "rhs isn't an instance" )
99+
96100 subScope . set ( this . _nameType . name , new DataEntity ( new AnyType ( ) ) )
97101 }
98102
99- const downstreamVal = this . downstreamExpr . eval ( subScope )
103+ const downstreamVal = this . downstreamExpr . eval ( ctx , subScope )
100104
101105 subScope . assertAllUsed ( )
102106
0 commit comments