mt-lang 0.3.6 → 0.3.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,7 @@ module MilkTea
53
53
  end
54
54
 
55
55
  def lower_direct_function_to_proc_expression(source_expression, source_function, env:, expected_type:)
56
- raise LoweringError, "function-to-proc coercion requires a direct function name" unless source_function.is_a?(IR::Name)
56
+ raise LoweringError.new("function-to-proc coercion requires a direct function name", line: 0, column: 0, path: @ctx.current_analysis_path) unless source_function.is_a?(IR::Name)
57
57
 
58
58
  proc_id = fresh_proc_symbol
59
59
  invoke_c_name = "#{@ctx.module_prefix}__proc_#{proc_id}__invoke"
@@ -424,7 +424,7 @@ module MilkTea
424
424
  if (binding = lookup_value(callee.name, env))
425
425
  return [:callable_value, nil, nil, binding[:type], nil] if callable_type?(binding[:type])
426
426
 
427
- raise LoweringError, "#{callee.name} is not callable"
427
+ raise LoweringError.new("#{callee.name} is not callable", line: 0, column: 0, path: @ctx.current_analysis_path)
428
428
  end
429
429
 
430
430
  if @ctx.functions.key?(callee.name)
@@ -451,7 +451,7 @@ module MilkTea
451
451
  end
452
452
 
453
453
  if type.is_a?(Types::GenericStructDefinition) || type.is_a?(Types::GenericVariantDefinition)
454
- raise LoweringError, "generic type #{callee.name} requires type arguments"
454
+ raise LoweringError.new("generic type #{callee.name} requires type arguments", line: 0, column: 0, path: @ctx.current_analysis_path)
455
455
  end
456
456
 
457
457
  emit_fn = @artifacts.emitted_declarations.find { |d| d.is_a?(IR::Function) && d.name == callee.name }
@@ -459,7 +459,7 @@ module MilkTea
459
459
  return [:function, emit_fn.linkage_name, nil, emit_fn.return_type, nil]
460
460
  end
461
461
 
462
- raise LoweringError, "unknown callee #{callee.name}"
462
+ raise LoweringError.new("unknown callee #{callee.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
463
463
  end
464
464
 
465
465
  def resolve_member_access_callee(callee, env, arguments)
@@ -477,7 +477,7 @@ module MilkTea
477
477
  end
478
478
  imported_type = imported_module.types[callee.member]
479
479
  if imported_type.is_a?(Types::GenericStructDefinition) || imported_type.is_a?(Types::GenericVariantDefinition)
480
- raise LoweringError, "generic type #{callee.receiver.name}.#{callee.member} requires type arguments"
480
+ raise LoweringError.new("generic type #{callee.receiver.name}.#{callee.member} requires type arguments", line: 0, column: 0, path: @ctx.current_analysis_path)
481
481
  end
482
482
 
483
483
  if imported_type.is_a?(Types::Struct) || imported_type.is_a?(Types::StringView) || task_type?(imported_type) || imported_type.is_a?(Types::Vector) || imported_type.is_a?(Types::Matrix) || imported_type.is_a?(Types::Quaternion)
@@ -518,7 +518,7 @@ module MilkTea
518
518
  end
519
519
  end
520
520
 
521
- raise LoweringError, "unknown associated function #{type_expr}.#{callee.member}"
521
+ raise LoweringError.new("unknown associated function #{type_expr}.#{callee.member}", line: 0, column: 0, path: @ctx.current_analysis_path)
522
522
  end
523
523
 
524
524
  resolved_receiver_type = infer_method_receiver_type(callee.receiver, env:, member_name: callee.member)
@@ -526,7 +526,7 @@ module MilkTea
526
526
  if dyn_type?(resolved_receiver_type)
527
527
  interface = resolved_receiver_type.interface_binding
528
528
  method_binding = interface.methods[callee.member]
529
- raise LoweringError, "no method '#{callee.member}' on interface #{interface.name}" unless method_binding
529
+ raise LoweringError.new("no method '#{callee.member}' on interface #{interface.name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless method_binding
530
530
  return [:dyn_method, nil, callee.receiver, method_binding, nil]
531
531
  end
532
532
 
@@ -611,7 +611,7 @@ module MilkTea
611
611
  member_type = field_receiver_type.respond_to?(:field) ? field_receiver_type.field(callee.member) : nil
612
612
  return [:callable_value, nil, nil, member_type, nil] if callable_type?(member_type)
613
613
 
614
- raise LoweringError, "unknown callee #{callee.receiver}.#{callee.member}"
614
+ raise LoweringError.new("unknown callee #{callee.receiver}.#{callee.member}", line: 0, column: 0, path: @ctx.current_analysis_path)
615
615
  end
616
616
 
617
617
  def resolve_specialization_callee(callee, env)
@@ -652,10 +652,10 @@ module MilkTea
652
652
  when "attribute_arg"
653
653
  return [:compile_time_builtin, "attribute_arg", nil, compile_time_builtin_specialization_function_type(callee)]
654
654
  when "adapt"
655
- raise LoweringError, "adapt requires exactly one type argument" unless callee.arguments.length == 1
655
+ raise LoweringError.new("adapt requires exactly one type argument", line: 0, column: 0, path: @ctx.current_analysis_path) unless callee.arguments.length == 1
656
656
 
657
657
  type_arg = callee.arguments.first.value
658
- raise LoweringError, "adapt type argument must be a type" unless type_arg.is_a?(AST::TypeRef)
658
+ raise LoweringError.new("adapt type argument must be a type", line: 0, column: 0, path: @ctx.current_analysis_path) unless type_arg.is_a?(AST::TypeRef)
659
659
 
660
660
  parts = type_arg.name.parts
661
661
  type_args = type_arg.arguments.map { |a| a.value }
@@ -689,14 +689,14 @@ module MilkTea
689
689
  return [:struct_literal, nil, nil, specialized_type] if specialized_type.is_a?(Types::Struct) || task_type?(specialized_type) || specialized_type.is_a?(Types::Vector) || specialized_type.is_a?(Types::Matrix) || specialized_type.is_a?(Types::Quaternion) || specialized_type.is_a?(Types::Simd)
690
690
  end
691
691
 
692
- raise LoweringError, "unsupported specialization callee"
692
+ raise LoweringError.new("unsupported specialization callee", line: 0, column: 0, path: @ctx.current_analysis_path)
693
693
  end
694
694
 
695
695
  def resolve_expression_callee(callee, env)
696
696
  callee_type = infer_expression_type(callee, env:)
697
697
  return [:callable_value, nil, nil, callee_type, nil] if callable_type?(callee_type)
698
698
 
699
- raise LoweringError, "unsupported callee #{callee.class.name}"
699
+ raise LoweringError.new("unsupported callee #{callee.class.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
700
700
  end
701
701
 
702
702
  def infer_expression_type(expression, env:, expected_type: nil)
@@ -707,7 +707,7 @@ module MilkTea
707
707
  case expression
708
708
  when AST::AwaitExpr
709
709
  task_type = infer_expression_type(expression.expression, env:)
710
- raise LoweringError, "await requires a Task value, got #{task_type}" unless task_type.is_a?(Types::Task)
710
+ raise LoweringError.new("await requires a Task value, got #{task_type}", line: 0, column: 0, path: @ctx.current_analysis_path) unless task_type.is_a?(Types::Task)
711
711
 
712
712
  task_type.result_type
713
713
  when AST::IntegerLiteral
@@ -895,7 +895,7 @@ module MilkTea
895
895
  :simd_lane_with
896
896
  callee_type.return_type
897
897
  else
898
- raise LoweringError, "unsupported call kind #{kind}"
898
+ raise LoweringError.new("unsupported call kind #{kind}", line: 0, column: 0, path: @ctx.current_analysis_path)
899
899
  end
900
900
  when AST::PrefixCast
901
901
  resolve_type_ref(expression.target_type)
@@ -907,14 +907,14 @@ module MilkTea
907
907
  resolve_default_specialization(expression, env:).target_type
908
908
  elsif (callable_resolution = resolve_specialized_callable_binding(expression, env:))
909
909
  callable_kind, function_binding, = callable_resolution
910
- raise LoweringError, "specialized method must be called" if callable_kind == :method
910
+ raise LoweringError.new("specialized method must be called", line: 0, column: 0, path: @ctx.current_analysis_path) if callable_kind == :method
911
911
 
912
912
  function_binding.type
913
913
  else
914
- raise LoweringError, "unsupported specialization"
914
+ raise LoweringError.new("unsupported specialization", line: 0, column: 0, path: @ctx.current_analysis_path)
915
915
  end
916
916
  when AST::RangeExpr
917
- raise LoweringError, "range expression is not valid in this context; use it as a for-loop iterable"
917
+ raise LoweringError.new("range expression is not valid in this context; use it as a for-loop iterable", line: 0, column: 0, path: @ctx.current_analysis_path)
918
918
  when AST::ExpressionList
919
919
  names = []
920
920
  element_types = []
@@ -932,7 +932,7 @@ module MilkTea
932
932
  when AST::DetachExpr
933
933
  Types::Handle.new
934
934
  else
935
- raise LoweringError, "unsupported expression type #{expression.class.name}"
935
+ raise LoweringError.new("unsupported expression type #{expression.class.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
936
936
  end
937
937
  end
938
938
 
@@ -1222,8 +1222,8 @@ module MilkTea
1222
1222
 
1223
1223
  def function_type_for_name(name)
1224
1224
  binding = @ctx.functions.fetch(name)
1225
- raise LoweringError, "generic function #{name} cannot be used as a value" if binding.type_params.any?
1226
- raise LoweringError, "foreign function #{name} cannot be used as a value" if foreign_function_binding?(binding)
1225
+ raise LoweringError.new("generic function #{name} cannot be used as a value", line: 0, column: 0, path: @ctx.current_analysis_path) if binding.type_params.any?
1226
+ raise LoweringError.new("foreign function #{name} cannot be used as a value", line: 0, column: 0, path: @ctx.current_analysis_path) if foreign_function_binding?(binding)
1227
1227
 
1228
1228
  binding.type
1229
1229
  end
@@ -1284,7 +1284,7 @@ module MilkTea
1284
1284
  target_type = resolve_type_ref(expression.arguments.fetch(0).value)
1285
1285
 
1286
1286
  explicit_default = resolve_explicit_default_binding(target_type, context: "default[#{target_type}]")
1287
- raise LoweringError, "default[#{target_type}] requires associated function #{target_type}.default()" unless explicit_default
1287
+ raise LoweringError.new("default[#{target_type}] requires associated function #{target_type}.default()", line: 0, column: 0, path: @ctx.current_analysis_path) unless explicit_default
1288
1288
 
1289
1289
  DefaultResolution.new(target_type:, binding: explicit_default.binding, callee_name: explicit_default.callee_name)
1290
1290
  end
@@ -1292,7 +1292,7 @@ module MilkTea
1292
1292
  def resolve_hash_specialization(expression, env:)
1293
1293
  target_type = resolve_type_ref(expression.arguments.fetch(0).value)
1294
1294
  explicit_hash = resolve_explicit_hash_binding(target_type, context: "hash[#{target_type}]")
1295
- raise LoweringError, "hash[#{target_type}] requires associated function #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint" unless explicit_hash
1295
+ raise LoweringError.new("hash[#{target_type}] requires associated function #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint", line: 0, column: 0, path: @ctx.current_analysis_path) unless explicit_hash
1296
1296
 
1297
1297
  HashResolution.new(target_type:, binding: explicit_hash.binding, callee_name: explicit_hash.callee_name)
1298
1298
  end
@@ -1300,7 +1300,7 @@ module MilkTea
1300
1300
  def resolve_equal_specialization(expression, env:)
1301
1301
  target_type = resolve_type_ref(expression.arguments.fetch(0).value)
1302
1302
  explicit_equal = resolve_explicit_equal_binding(target_type, context: "equal[#{target_type}]")
1303
- raise LoweringError, "equal[#{target_type}] requires associated function #{target_type}.equal(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> bool" unless explicit_equal
1303
+ raise LoweringError.new("equal[#{target_type}] requires associated function #{target_type}.equal(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> bool", line: 0, column: 0, path: @ctx.current_analysis_path) unless explicit_equal
1304
1304
 
1305
1305
  EqualResolution.new(target_type:, binding: explicit_equal.binding, callee_name: explicit_equal.callee_name)
1306
1306
  end
@@ -1308,7 +1308,7 @@ module MilkTea
1308
1308
  def resolve_order_specialization(expression, env:)
1309
1309
  target_type = resolve_type_ref(expression.arguments.fetch(0).value)
1310
1310
  explicit_order = resolve_explicit_order_binding(target_type, context: "order[#{target_type}]")
1311
- raise LoweringError, "order[#{target_type}] requires associated function #{target_type}.order(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> int" unless explicit_order
1311
+ raise LoweringError.new("order[#{target_type}] requires associated function #{target_type}.order(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> int", line: 0, column: 0, path: @ctx.current_analysis_path) unless explicit_order
1312
1312
 
1313
1313
  OrderResolution.new(target_type:, binding: explicit_order.binding, callee_name: explicit_order.callee_name)
1314
1314
  end
@@ -1316,9 +1316,9 @@ module MilkTea
1316
1316
  def resolve_explicit_default_binding(target_type, context:)
1317
1317
  requirement_message = "#{context} requires associated function #{target_type}.default()"
1318
1318
  resolve_explicit_associated_binding(target_type, "default", requirement_message:) do |method_binding, _method_analysis, _method_entry_receiver_type|
1319
- raise LoweringError, "#{context} requires #{target_type}.default() to take 0 arguments" unless method_binding.type.params.empty?
1319
+ raise LoweringError.new("#{context} requires #{target_type}.default() to take 0 arguments", line: 0, column: 0, path: @ctx.current_analysis_path) unless method_binding.type.params.empty?
1320
1320
  unless method_binding.type.return_type == target_type
1321
- raise LoweringError, "#{context} requires #{target_type}.default() to return #{target_type}, got #{method_binding.type.return_type}"
1321
+ raise LoweringError.new("#{context} requires #{target_type}.default() to return #{target_type}, got #{method_binding.type.return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
1322
1322
  end
1323
1323
  end
1324
1324
  end
@@ -1327,10 +1327,10 @@ module MilkTea
1327
1327
  requirement_message = "#{context} requires associated function #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint"
1328
1328
  resolve_explicit_associated_binding(target_type, "hash", requirement_message:) do |method_binding, _method_analysis, _method_entry_receiver_type|
1329
1329
  unless method_binding.type.params.map(&:type) == [const_pointer_to(target_type)]
1330
- raise LoweringError, "#{context} requires #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint"
1330
+ raise LoweringError.new("#{context} requires #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint", line: 0, column: 0, path: @ctx.current_analysis_path)
1331
1331
  end
1332
1332
  unless method_binding.type.return_type == @ctx.types.fetch("uint")
1333
- raise LoweringError, "#{context} requires #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint, got #{method_binding.type.return_type}"
1333
+ raise LoweringError.new("#{context} requires #{target_type}.hash(value: const_ptr[#{target_type}]) -> uint, got #{method_binding.type.return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
1334
1334
  end
1335
1335
  end
1336
1336
  end
@@ -1340,10 +1340,10 @@ module MilkTea
1340
1340
  resolve_explicit_associated_binding(target_type, "equal", requirement_message:) do |method_binding, _method_analysis, _method_entry_receiver_type|
1341
1341
  expected_param_types = [const_pointer_to(target_type), const_pointer_to(target_type)]
1342
1342
  unless method_binding.type.params.map(&:type) == expected_param_types
1343
- raise LoweringError, "#{context} requires #{target_type}.equal(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> bool"
1343
+ raise LoweringError.new("#{context} requires #{target_type}.equal(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> bool", line: 0, column: 0, path: @ctx.current_analysis_path)
1344
1344
  end
1345
1345
  unless method_binding.type.return_type == @ctx.types.fetch("bool")
1346
- raise LoweringError, "#{context} requires #{target_type}.equal(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> bool, got #{method_binding.type.return_type}"
1346
+ raise LoweringError.new("#{context} requires #{target_type}.equal(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> bool, got #{method_binding.type.return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
1347
1347
  end
1348
1348
  end
1349
1349
  end
@@ -1353,10 +1353,10 @@ module MilkTea
1353
1353
  resolve_explicit_associated_binding(target_type, "order", requirement_message:) do |method_binding, _method_analysis, _method_entry_receiver_type|
1354
1354
  expected_param_types = [const_pointer_to(target_type), const_pointer_to(target_type)]
1355
1355
  unless method_binding.type.params.map(&:type) == expected_param_types
1356
- raise LoweringError, "#{context} requires #{target_type}.order(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> int"
1356
+ raise LoweringError.new("#{context} requires #{target_type}.order(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> int", line: 0, column: 0, path: @ctx.current_analysis_path)
1357
1357
  end
1358
1358
  unless method_binding.type.return_type == @ctx.types.fetch("int")
1359
- raise LoweringError, "#{context} requires #{target_type}.order(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> int, got #{method_binding.type.return_type}"
1359
+ raise LoweringError.new("#{context} requires #{target_type}.order(left: const_ptr[#{target_type}], right: const_ptr[#{target_type}]) -> int, got #{method_binding.type.return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
1360
1360
  end
1361
1361
  end
1362
1362
  end
@@ -1373,7 +1373,7 @@ module MilkTea
1373
1373
  ) if length_binding && append_binding
1374
1374
 
1375
1375
  if length_binding || append_binding
1376
- raise LoweringError, "#{context} requires methods #{target_type}.format_len() -> ptr_uint and #{target_type}.append_format(output: ref[std.string.String]) -> void"
1376
+ raise LoweringError.new("#{context} requires methods #{target_type}.format_len() -> ptr_uint and #{target_type}.append_format(output: ref[std.string.String]) -> void", line: 0, column: 0, path: @ctx.current_analysis_path)
1377
1377
  end
1378
1378
 
1379
1379
  nil
@@ -1382,10 +1382,10 @@ module MilkTea
1382
1382
  def resolve_explicit_format_len_binding(target_type, context:)
1383
1383
  requirement_message = "#{context} requires method #{target_type}.format_len() -> ptr_uint"
1384
1384
  resolve_explicit_instance_binding(target_type, "format_len", requirement_message:) do |method_binding, _method_analysis, _method_entry_receiver_type|
1385
- raise LoweringError, "#{context} requires #{target_type}.format_len() to take 0 arguments" unless method_binding.type.params.empty?
1386
- raise LoweringError, "#{context} requires #{target_type}.format_len() to be non-editable" if method_binding.type.receiver_editable
1385
+ raise LoweringError.new("#{context} requires #{target_type}.format_len() to take 0 arguments", line: 0, column: 0, path: @ctx.current_analysis_path) unless method_binding.type.params.empty?
1386
+ raise LoweringError.new("#{context} requires #{target_type}.format_len() to be non-editable", line: 0, column: 0, path: @ctx.current_analysis_path) if method_binding.type.receiver_editable
1387
1387
  unless method_binding.type.return_type == @ctx.types.fetch("ptr_uint")
1388
- raise LoweringError, "#{context} requires #{target_type}.format_len() -> ptr_uint, got #{method_binding.type.return_type}"
1388
+ raise LoweringError.new("#{context} requires #{target_type}.format_len() -> ptr_uint, got #{method_binding.type.return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
1389
1389
  end
1390
1390
  end
1391
1391
  end
@@ -1393,12 +1393,12 @@ module MilkTea
1393
1393
  def resolve_explicit_format_append_binding(target_type, context:)
1394
1394
  requirement_message = "#{context} requires method #{target_type}.append_format(output: ref[std.string.String]) -> void"
1395
1395
  resolve_explicit_instance_binding(target_type, "append_format", requirement_message:) do |method_binding, _method_analysis, _method_entry_receiver_type|
1396
- raise LoweringError, "#{context} requires #{target_type}.append_format() to be non-editable" if method_binding.type.receiver_editable
1396
+ raise LoweringError.new("#{context} requires #{target_type}.append_format() to be non-editable", line: 0, column: 0, path: @ctx.current_analysis_path) if method_binding.type.receiver_editable
1397
1397
  unless method_binding.type.params.length == 1 && string_builder_ref_type?(method_binding.type.params.first.type)
1398
- raise LoweringError, "#{context} requires #{target_type}.append_format(output: ref[std.string.String]) -> void"
1398
+ raise LoweringError.new("#{context} requires #{target_type}.append_format(output: ref[std.string.String]) -> void", line: 0, column: 0, path: @ctx.current_analysis_path)
1399
1399
  end
1400
1400
  unless method_binding.type.return_type == @ctx.types.fetch("void")
1401
- raise LoweringError, "#{context} requires #{target_type}.append_format(output: ref[std.string.String]) -> void, got #{method_binding.type.return_type}"
1401
+ raise LoweringError.new("#{context} requires #{target_type}.append_format(output: ref[std.string.String]) -> void, got #{method_binding.type.return_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
1402
1402
  end
1403
1403
  end
1404
1404
  end
@@ -1420,7 +1420,7 @@ module MilkTea
1420
1420
 
1421
1421
  method_analysis, method_ast = method_entry
1422
1422
  method_binding = method_analysis.methods.fetch(method_entry_receiver_type).fetch(method_analysis_key(method_ast))
1423
- raise LoweringError, requirement_message unless method_binding.type.receiver_type.nil?
1423
+ raise LoweringError.new(requirement_message, line: 0, column: 0, path: @ctx.current_analysis_path) unless method_binding.type.receiver_type.nil?
1424
1424
 
1425
1425
  method_binding = instantiate_function_binding_with_receiver(method_binding, [], receiver_type: target_type) if method_binding.type_params.any?
1426
1426
  yield method_binding, method_analysis, method_entry_receiver_type
@@ -1441,7 +1441,7 @@ module MilkTea
1441
1441
  when "order"
1442
1442
  ExplicitOrderBinding.new(binding: method_binding, callee_name:)
1443
1443
  else
1444
- raise LoweringError, "unsupported associated hook #{method_name}"
1444
+ raise LoweringError.new("unsupported associated hook #{method_name}", line: 0, column: 0, path: @ctx.current_analysis_path)
1445
1445
  end
1446
1446
  end
1447
1447
 
@@ -1457,7 +1457,7 @@ module MilkTea
1457
1457
 
1458
1458
  method_analysis, method_ast = method_entry
1459
1459
  method_binding = method_analysis.methods.fetch(method_entry_receiver_type).fetch(method_analysis_key(method_ast))
1460
- raise LoweringError, requirement_message if method_binding.type.receiver_type.nil?
1460
+ raise LoweringError.new(requirement_message, line: 0, column: 0, path: @ctx.current_analysis_path) if method_binding.type.receiver_type.nil?
1461
1461
 
1462
1462
  method_binding = instantiate_function_binding_with_receiver(method_binding, [], receiver_type: target_type) if method_binding.type_params.any?
1463
1463
  yield method_binding, method_analysis, method_entry_receiver_type
@@ -1489,7 +1489,7 @@ module MilkTea
1489
1489
  when AST::IntegerLiteral, AST::FloatLiteral
1490
1490
  Types::LiteralTypeArg.new(argument.value)
1491
1491
  else
1492
- raise LoweringError, "unsupported type argument #{argument.class.name}"
1492
+ raise LoweringError.new("unsupported type argument #{argument.class.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
1493
1493
  end
1494
1494
  end
1495
1495
 
@@ -1532,7 +1532,7 @@ module MilkTea
1532
1532
  imported_module = @ctx.imports[import_name]
1533
1533
  return unless imported_module
1534
1534
  if imported_module.private_value?(value_name)
1535
- raise LoweringError, "#{import_name}.#{value_name} is private to module #{imported_module.name}"
1535
+ raise LoweringError.new("#{import_name}.#{value_name} is private to module #{imported_module.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
1536
1536
  end
1537
1537
 
1538
1538
  binding = imported_module.values[value_name]
@@ -1996,7 +1996,7 @@ module MilkTea
1996
1996
 
1997
1997
  def specialize_function_binding(binding, arguments, env, receiver_type: nil)
1998
1998
  return binding if binding.type_params.empty?
1999
- raise LoweringError, "generic function #{binding.name} must be called" unless arguments
1999
+ raise LoweringError.new("generic function #{binding.name} must be called", line: 0, column: 0, path: @ctx.current_analysis_path) unless arguments
2000
2000
 
2001
2001
  type_arguments = infer_function_type_arguments(binding, arguments, env, receiver_type:)
2002
2002
  instantiate_function_binding(binding, type_arguments)
@@ -2004,25 +2004,25 @@ module MilkTea
2004
2004
 
2005
2005
  def instantiate_function_binding_with_receiver(binding, explicit_type_arguments, receiver_type: nil)
2006
2006
  if binding.type_params.empty?
2007
- raise LoweringError, "function #{binding.name} is not generic and cannot be specialized"
2007
+ raise LoweringError.new("function #{binding.name} is not generic and cannot be specialized", line: 0, column: 0, path: @ctx.current_analysis_path)
2008
2008
  end
2009
2009
 
2010
2010
  receiver_substitutions = infer_receiver_type_substitutions(binding, receiver_type)
2011
2011
  remaining_type_params = binding.type_params.reject { |name| receiver_substitutions.key?(name) }
2012
2012
  unless remaining_type_params.length == explicit_type_arguments.length
2013
- raise LoweringError, "function #{binding.name} expects #{remaining_type_params.length} type arguments, got #{explicit_type_arguments.length}"
2013
+ raise LoweringError.new("function #{binding.name} expects #{remaining_type_params.length} type arguments, got #{explicit_type_arguments.length}", line: 0, column: 0, path: @ctx.current_analysis_path)
2014
2014
  end
2015
2015
 
2016
2016
  substitutions = receiver_substitutions.dup
2017
2017
  remaining_type_params.zip(explicit_type_arguments).each do |name, type_argument|
2018
- raise LoweringError, "generic function #{binding.name} cannot be instantiated with ref types" if contains_ref_type?(type_argument)
2018
+ raise LoweringError.new("generic function #{binding.name} cannot be instantiated with ref types", line: 0, column: 0, path: @ctx.current_analysis_path) if contains_ref_type?(type_argument)
2019
2019
 
2020
2020
  substitutions[name] = type_argument
2021
2021
  end
2022
2022
 
2023
2023
  type_arguments = binding.type_params.map do |name|
2024
2024
  inferred = substitutions[name]
2025
- raise LoweringError, "cannot infer type argument #{name} for function #{binding.name}" unless inferred
2025
+ raise LoweringError.new("cannot infer type argument #{name} for function #{binding.name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless inferred
2026
2026
 
2027
2027
  inferred
2028
2028
  end
@@ -2032,15 +2032,15 @@ module MilkTea
2032
2032
 
2033
2033
  def instantiate_function_binding(binding, type_arguments)
2034
2034
  if binding.type_params.empty?
2035
- raise LoweringError, "function #{binding.name} is not generic and cannot be specialized"
2035
+ raise LoweringError.new("function #{binding.name} is not generic and cannot be specialized", line: 0, column: 0, path: @ctx.current_analysis_path)
2036
2036
  end
2037
2037
 
2038
2038
  unless binding.type_params.length == type_arguments.length
2039
- raise LoweringError, "function #{binding.name} expects #{binding.type_params.length} type arguments, got #{type_arguments.length}"
2039
+ raise LoweringError.new("function #{binding.name} expects #{binding.type_params.length} type arguments, got #{type_arguments.length}", line: 0, column: 0, path: @ctx.current_analysis_path)
2040
2040
  end
2041
2041
 
2042
2042
  if type_arguments.any? { |type_argument| contains_ref_type?(type_argument) }
2043
- raise LoweringError, "generic function #{binding.name} cannot be instantiated with ref types"
2043
+ raise LoweringError.new("generic function #{binding.name} cannot be instantiated with ref types", line: 0, column: 0, path: @ctx.current_analysis_path)
2044
2044
  end
2045
2045
 
2046
2046
  key = type_arguments.freeze
@@ -2071,12 +2071,12 @@ module MilkTea
2071
2071
  def validate_function_type_param_constraints!(binding, substitutions)
2072
2072
  binding.type_param_constraints.each do |name, constraints|
2073
2073
  actual_type = substitutions[name]
2074
- raise LoweringError, "cannot infer type argument #{name} for function #{binding.name}" unless actual_type
2074
+ raise LoweringError.new("cannot infer type argument #{name} for function #{binding.name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless actual_type
2075
2075
 
2076
2076
  constraints.interfaces.each do |interface|
2077
2077
  next if type_implements_interface?(actual_type, interface)
2078
2078
 
2079
- raise LoweringError, "type #{actual_type} does not implement interface #{interface.name} for function #{binding.name}"
2079
+ raise LoweringError.new("type #{actual_type} does not implement interface #{interface.name} for function #{binding.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
2080
2080
  end
2081
2081
  end
2082
2082
  end
@@ -2102,7 +2102,7 @@ module MilkTea
2102
2102
  def infer_function_type_arguments(binding, arguments, env, receiver_type: nil)
2103
2103
  expected_params = binding.type.params
2104
2104
  unless call_arity_matches?(binding.type, arguments.length)
2105
- raise LoweringError, arity_error_message(binding.type, binding.name, arguments.length)
2105
+ raise LoweringError.new(arity_error_message(binding.type, binding.name, arguments.length), line: 0, column: 0, path: @ctx.current_analysis_path)
2106
2106
  end
2107
2107
 
2108
2108
  substitutions = infer_receiver_type_substitutions(binding, receiver_type)
@@ -2122,7 +2122,7 @@ module MilkTea
2122
2122
 
2123
2123
  binding.type_params.map do |name|
2124
2124
  inferred = substitutions[name]
2125
- raise LoweringError, "cannot infer type argument #{name} for function #{binding.name}" unless inferred
2125
+ raise LoweringError.new("cannot infer type argument #{name} for function #{binding.name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless inferred
2126
2126
 
2127
2127
  inferred
2128
2128
  end
@@ -2153,7 +2153,7 @@ module MilkTea
2153
2153
 
2154
2154
  expected_names = generic_type.type_params
2155
2155
  unless names == expected_names
2156
- raise LoweringError, "extending target #{type_ref} must use the receiver type parameters directly"
2156
+ raise LoweringError.new("extending target #{type_ref} must use the receiver type parameters directly", line: 0, column: 0, path: @ctx.current_analysis_path)
2157
2157
  end
2158
2158
 
2159
2159
  expected_names
@@ -2168,7 +2168,7 @@ module MilkTea
2168
2168
  value.name.parts.first
2169
2169
  end
2170
2170
 
2171
- raise LoweringError, "extending target #{type_ref} must use the receiver type parameters directly" if names.any?(&:nil?)
2171
+ raise LoweringError.new("extending target #{type_ref} must use the receiver type parameters directly", line: 0, column: 0, path: @ctx.current_analysis_path) if names.any?(&:nil?)
2172
2172
 
2173
2173
  names
2174
2174
  end
@@ -2179,7 +2179,7 @@ module MilkTea
2179
2179
  case declared_receiver_type
2180
2180
  when Types::Nullable
2181
2181
  unless receiver_type.is_a?(Types::Nullable)
2182
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2182
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2183
2183
  end
2184
2184
 
2185
2185
  infer_receiver_type_substitutions(
@@ -2190,7 +2190,7 @@ module MilkTea
2190
2190
  return {} unless declared_receiver_type.definition.is_a?(Types::GenericStructDefinition)
2191
2191
 
2192
2192
  unless receiver_type.is_a?(Types::StructInstance) && receiver_type.definition == declared_receiver_type.definition
2193
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2193
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2194
2194
  end
2195
2195
 
2196
2196
  declared_receiver_type.definition.type_params.zip(receiver_type.arguments).to_h
@@ -2198,20 +2198,20 @@ module MilkTea
2198
2198
  return {} unless declared_receiver_type.definition.is_a?(Types::GenericVariantDefinition)
2199
2199
 
2200
2200
  unless receiver_type.is_a?(Types::VariantInstance) && receiver_type.definition == declared_receiver_type.definition
2201
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2201
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2202
2202
  end
2203
2203
 
2204
2204
  declared_receiver_type.definition.type_params.zip(receiver_type.arguments).to_h
2205
2205
  when Types::GenericInstance
2206
2206
  unless receiver_type.is_a?(Types::GenericInstance) && receiver_type.name == declared_receiver_type.name && receiver_type.arguments.length == declared_receiver_type.arguments.length
2207
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2207
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2208
2208
  end
2209
2209
 
2210
2210
  declared_receiver_type.arguments.zip(receiver_type.arguments).each_with_object({}) do |(declared_argument, actual_argument), substitutions|
2211
2211
  if declared_argument.is_a?(Types::TypeVar)
2212
2212
  substitutions[declared_argument.name] = actual_argument
2213
2213
  elsif declared_argument != actual_argument
2214
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2214
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2215
2215
  end
2216
2216
  end
2217
2217
  when Types::Span
@@ -2221,7 +2221,7 @@ module MilkTea
2221
2221
  if declared_receiver_type.element_type.is_a?(Types::TypeVar)
2222
2222
  substitutions[declared_receiver_type.element_type.name] = receiver_type.element_type
2223
2223
  elsif declared_receiver_type.element_type != receiver_type.element_type
2224
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2224
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2225
2225
  end
2226
2226
  substitutions
2227
2227
  when Types::Task
@@ -2231,7 +2231,7 @@ module MilkTea
2231
2231
  if declared_receiver_type.result_type.is_a?(Types::TypeVar)
2232
2232
  substitutions[declared_receiver_type.result_type.name] = receiver_type.result_type
2233
2233
  elsif declared_receiver_type.result_type != receiver_type.result_type
2234
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2234
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2235
2235
  end
2236
2236
  substitutions
2237
2237
  when Types::SoA
@@ -2241,7 +2241,7 @@ module MilkTea
2241
2241
  if declared_receiver_type.element_type.is_a?(Types::TypeVar)
2242
2242
  substitutions[declared_receiver_type.element_type.name] = receiver_type.element_type
2243
2243
  elsif declared_receiver_type.element_type != receiver_type.element_type
2244
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2244
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2245
2245
  end
2246
2246
  substitutions
2247
2247
  when Types::Simd
@@ -2251,7 +2251,7 @@ module MilkTea
2251
2251
  if declared_receiver_type.element_type.is_a?(Types::TypeVar)
2252
2252
  substitutions[declared_receiver_type.element_type.name] = receiver_type.element_type
2253
2253
  elsif declared_receiver_type.element_type != receiver_type.element_type
2254
- raise LoweringError, "cannot use method #{binding.name} with receiver #{receiver_type}"
2254
+ raise LoweringError.new("cannot use method #{binding.name} with receiver #{receiver_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2255
2255
  end
2256
2256
  substitutions
2257
2257
  else
@@ -2264,7 +2264,7 @@ module MilkTea
2264
2264
  when Types::TypeVar
2265
2265
  existing = substitutions[pattern_type.name]
2266
2266
  if existing && existing != actual_type
2267
- raise LoweringError, "conflicting type argument #{pattern_type.name} for function #{function_name}: got #{existing} and #{actual_type}"
2267
+ raise LoweringError.new("conflicting type argument #{pattern_type.name} for function #{function_name}: got #{existing} and #{actual_type}", line: 0, column: 0, path: @ctx.current_analysis_path)
2268
2268
  end
2269
2269
 
2270
2270
  substitutions[pattern_type.name] ||= actual_type
@@ -2389,7 +2389,7 @@ module MilkTea
2389
2389
  def const_declaration_for_module(module_name, name)
2390
2390
  analysis = @program.analyses_by_module_name.fetch(module_name)
2391
2391
  declaration = analysis.ast.declarations.find { |decl| decl.is_a?(AST::ConstDecl) && decl.name == name }
2392
- raise LoweringError, "unknown constant #{analysis.module_name}.#{name}" unless declaration
2392
+ raise LoweringError.new("unknown constant #{analysis.module_name}.#{name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless declaration
2393
2393
 
2394
2394
  declaration
2395
2395
  end
@@ -2424,7 +2424,7 @@ module MilkTea
2424
2424
 
2425
2425
  if type_ref.is_a?(AST::DynType)
2426
2426
  interface = resolve_interface_ref(type_ref.interface)
2427
- raise LoweringError, "generic interface requires type arguments" if interface.respond_to?(:instantiate)
2427
+ raise LoweringError.new("generic interface requires type arguments", line: 0, column: 0, path: @ctx.current_analysis_path) if interface.respond_to?(:instantiate)
2428
2428
  type_arguments = interface.respond_to?(:type_arguments) ? (interface.type_arguments || []) : []
2429
2429
  return Types::Dyn.new(interface, type_arguments)
2430
2430
  end
@@ -2450,7 +2450,7 @@ module MilkTea
2450
2450
  name = parts.join(".")
2451
2451
  args = type_ref.arguments.map { |argument| resolve_type_argument(argument.value, type_params:) }
2452
2452
  if name != "ref" && args.any? { |argument| contains_ref_type?(argument) && !stored_ref_supported_type?(argument) }
2453
- raise LoweringError, "ref types cannot be nested inside #{name}"
2453
+ raise LoweringError.new("ref types cannot be nested inside #{name}", line: 0, column: 0, path: @ctx.current_analysis_path)
2454
2454
  end
2455
2455
  if name == "Task"
2456
2456
  validate_generic_type!(name, args)
@@ -2474,8 +2474,8 @@ module MilkTea
2474
2474
  type_params.fetch(parts.first)
2475
2475
  elsif parts.length == 1
2476
2476
  type = @ctx.types[parts.first]
2477
- raise LoweringError, "unknown type #{parts.first}" unless type
2478
- raise LoweringError, "generic type #{parts.first} requires type arguments" if type.is_a?(Types::GenericStructDefinition) || type.is_a?(Types::GenericVariantDefinition)
2477
+ raise LoweringError.new("unknown type #{parts.first}", line: 0, column: 0, path: @ctx.current_analysis_path) unless type
2478
+ raise LoweringError.new("generic type #{parts.first} requires type arguments", line: 0, column: 0, path: @ctx.current_analysis_path) if type.is_a?(Types::GenericStructDefinition) || type.is_a?(Types::GenericVariantDefinition)
2479
2479
 
2480
2480
  type
2481
2481
  elsif parts.length >= 2
@@ -2485,25 +2485,25 @@ module MilkTea
2485
2485
  if @ctx.imports.key?(parts.first)
2486
2486
  imported_module = @ctx.imports.fetch(parts.first)
2487
2487
  if imported_module.private_type?(parts.last)
2488
- raise LoweringError, "#{parts.first}.#{parts.last} is private to module #{imported_module.name}"
2488
+ raise LoweringError.new("#{parts.first}.#{parts.last} is private to module #{imported_module.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
2489
2489
  end
2490
2490
 
2491
2491
  type = imported_module.types[parts.last]
2492
- raise LoweringError, "unknown type #{type_ref.name}" unless type
2493
- raise LoweringError, "generic type #{type_ref.name} requires type arguments" if type.is_a?(Types::GenericStructDefinition) || type.is_a?(Types::GenericVariantDefinition)
2492
+ raise LoweringError.new("unknown type #{type_ref.name}", line: 0, column: 0, path: @ctx.current_analysis_path) unless type
2493
+ raise LoweringError.new("generic type #{type_ref.name} requires type arguments", line: 0, column: 0, path: @ctx.current_analysis_path) if type.is_a?(Types::GenericStructDefinition) || type.is_a?(Types::GenericVariantDefinition)
2494
2494
  elsif @type_resolution_env && (field_type = resolve_field_handle_type_ref(parts))
2495
2495
  type = field_type
2496
2496
  else
2497
- raise LoweringError, "unknown type #{type_ref.name}"
2497
+ raise LoweringError.new("unknown type #{type_ref.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
2498
2498
  end
2499
2499
  end
2500
2500
 
2501
2501
  type
2502
2502
  else
2503
- raise LoweringError, "unknown type #{type_ref.name}"
2503
+ raise LoweringError.new("unknown type #{type_ref.name}", line: 0, column: 0, path: @ctx.current_analysis_path)
2504
2504
  end
2505
2505
 
2506
- raise LoweringError, "ref types are non-null and cannot be nullable" if type_ref.nullable && ref_type?(base)
2506
+ raise LoweringError.new("ref types are non-null and cannot be nullable", line: 0, column: 0, path: @ctx.current_analysis_path) if type_ref.nullable && ref_type?(base)
2507
2507
 
2508
2508
  type_ref.nullable ? Types::Registry.nullable(base) : base
2509
2509
  end
@@ -2580,10 +2580,10 @@ module MilkTea
2580
2580
  elsif parts.length == 2 && @ctx.imports.key?(parts.first)
2581
2581
  @ctx.imports.fetch(parts.first).interfaces[parts.last]
2582
2582
  end
2583
- raise LoweringError, "unknown interface #{interface_ref}" unless interface
2583
+ raise LoweringError.new("unknown interface #{interface_ref}", line: 0, column: 0, path: @ctx.current_analysis_path) unless interface
2584
2584
 
2585
2585
  if interface_ref.type_arguments.any?
2586
- raise LoweringError, "interface #{interface.name} is not generic" unless interface.respond_to?(:instantiate)
2586
+ raise LoweringError.new("interface #{interface.name} is not generic", line: 0, column: 0, path: @ctx.current_analysis_path) unless interface.respond_to?(:instantiate)
2587
2587
  type_args = interface_ref.type_arguments.map { |arg| resolve_type_ref(arg) }
2588
2588
  interface.instantiate(type_args)
2589
2589
  else
@@ -43,7 +43,7 @@ module MilkTea
43
43
  when :str_buffer_as_cstr
44
44
  [@ctx.types.fetch("cstr"), []]
45
45
  else
46
- raise LoweringError, "unsupported str_buffer method #{kind}"
46
+ raise LoweringError.new("unsupported str_buffer method #{kind}", line: 0, column: 0, path: @ctx.current_analysis_path)
47
47
  end
48
48
 
49
49
  Types::Registry.function(