@@ -1299,6 +1299,14 @@ extension StmtTypeChecker {
12991299 tableColumns: borrowing Columns ,
13001300 tableName: Substring
13011301 ) -> Type {
1302+ let nominal : Type = . nominal( column. type. name. value)
1303+
1304+ var type : Type = if let alias = column. type. alias {
1305+ . alias( nominal, . explicit( alias. identifier. value) )
1306+ } else {
1307+ nominal
1308+ }
1309+
13021310 var isNotNullable = false
13031311 for constraint in column. constraints {
13041312 switch constraint. kind {
@@ -1309,6 +1317,12 @@ extension StmtTypeChecker {
13091317 case let . check( expr) :
13101318 inNewEnvironment { typeChecker in
13111319 typeChecker. env. import ( columns: tableColumns)
1320+ // Technically this could be incorrect if the check
1321+ // comes before the not null. But it'll do.
1322+ typeChecker. env. import (
1323+ column: column. name. value,
1324+ with: isNotNullable ? type : . optional( type)
1325+ )
13121326 _ = typeChecker. typeCheck ( expr)
13131327 }
13141328 case let . default( expr) :
@@ -1353,19 +1367,7 @@ extension StmtTypeChecker {
13531367 ) )
13541368 }
13551369
1356- let nominal : Type = . nominal( column. type. name. value)
1357-
1358- let type : Type = if let alias = column. type. alias {
1359- . alias( nominal, . explicit( alias. identifier. value) )
1360- } else {
1361- nominal
1362- }
1363-
1364- if isNotNullable {
1365- return type
1366- } else {
1367- return . optional( type)
1368- }
1370+ return isNotNullable ? type : . optional( type)
13691371 }
13701372
13711373 private mutating func typeCheck(
0 commit comments