Class: Steep::Signature::Validator
- Defined in:
- lib/steep/signature/validator.rb
Constant Summary collapse
- Location =
RBS::Location
- Declarations =
RBS::AST::Declarations
Instance Attribute Summary collapse
-
#checker ⇒ Object
readonly
Returns the value of attribute checker.
-
#context ⇒ Object
readonly
Returns the value of attribute context.
Instance Method Summary collapse
- #ancestor_to_type(ancestor) ⇒ Object
- #builder ⇒ Object
- #each_error(&block) ⇒ Object
- #each_method_type(definition) ⇒ Object
- #each_variable_type(definition) ⇒ Object
- #env ⇒ Object
- #factory ⇒ Object
- #has_error? ⇒ Boolean
-
#initialize(checker:) ⇒ Validator
constructor
A new instance of Validator.
- #latest_context ⇒ Object
- #mixin_constraints(definition, mixin_ancestors, immediate_self_types:) ⇒ Object
- #no_error? ⇒ Boolean
- #push_context(self_type: , class_type: , instance_type: ) ⇒ Object
- #rescue_validation_errors(type_name = nil) ⇒ Object
- #type_name_resolver ⇒ Object
- #validate ⇒ Object
- #validate_alias ⇒ Object
- #validate_ancestor_application(name, ancestor) ⇒ Object
- #validate_const ⇒ Object
- #validate_decl ⇒ Object
- #validate_definition_type(definition) ⇒ Object
- #validate_global ⇒ Object
- #validate_one_alias(name, entry = env.type_alias_decls.fetch(name)) ⇒ Object
- #validate_one_class(name) ⇒ Object
- #validate_one_class_alias(name, entry) ⇒ Object
- #validate_one_class_decl(name, entry) ⇒ Object
- #validate_one_constant(name, entry) ⇒ Object
- #validate_one_global(name, entry) ⇒ Object
- #validate_one_interface(name) ⇒ Object
- #validate_type(type) ⇒ Object
- #validate_type_0(type) ⇒ Object
- #validate_type_application(type) ⇒ Object
- #validate_type_application_constraints(type_name, type_params, type_args, location:) ⇒ Object
- #validate_type_name_deprecation(type_name, location) ⇒ Object
- #validate_type_params(type_name, type_params) ⇒ Object
- #validator ⇒ Object
Constructor Details
#initialize(checker:) ⇒ Validator
Returns a new instance of Validator.
10 11 12 13 14 |
# File 'lib/steep/signature/validator.rb', line 10 def initialize(checker:) @checker = checker @errors = [] @context = [] end |
Instance Attribute Details
#checker ⇒ Object (readonly)
Returns the value of attribute checker.
7 8 9 |
# File 'lib/steep/signature/validator.rb', line 7 def checker @checker end |
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/steep/signature/validator.rb', line 8 def context @context end |
Instance Method Details
#ancestor_to_type(ancestor) ⇒ Object
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/steep/signature/validator.rb', line 182 def ancestor_to_type(ancestor) case ancestor when RBS::Definition::Ancestor::Instance args = ancestor.args.map {|type| checker.factory.type(type) } case when ancestor.name.interface? AST::Types::Name::Interface.new(name: ancestor.name, args: args) when ancestor.name.class? AST::Types::Name::Instance.new(name: ancestor.name, args: args) else raise "#{ancestor.name}" end else raise "Unexpected ancestor: #{ancestor.inspect}" end end |
#builder ⇒ Object
47 48 49 |
# File 'lib/steep/signature/validator.rb', line 47 def builder checker.factory.definition_builder end |
#each_error(&block) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/steep/signature/validator.rb', line 35 def each_error(&block) if block @errors.each(&block) else enum_for :each_error end end |
#each_method_type(definition) ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/steep/signature/validator.rb', line 232 def each_method_type(definition) type_name = definition.type_name definition.methods.each_value do |method| if method.defined_in == type_name method.method_types.each do |method_type| yield method_type end end end end |
#each_variable_type(definition) ⇒ Object
244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/steep/signature/validator.rb', line 244 def each_variable_type(definition) type_name = definition.type_name definition.instance_variables.each_value do |var| if var.declared_in == type_name yield var.type end end definition.class_variables.each_value do |var| if var.declared_in == type_name yield var.type end end end |
#env ⇒ Object
43 44 45 |
# File 'lib/steep/signature/validator.rb', line 43 def env checker.factory.env end |
#factory ⇒ Object
59 60 61 |
# File 'lib/steep/signature/validator.rb', line 59 def factory checker.factory end |
#has_error? ⇒ Boolean
27 28 29 |
# File 'lib/steep/signature/validator.rb', line 27 def has_error? !no_error? end |
#latest_context ⇒ Object
23 24 25 |
# File 'lib/steep/signature/validator.rb', line 23 def latest_context context.last || [nil, nil, nil] end |
#mixin_constraints(definition, mixin_ancestors, immediate_self_types:) ⇒ Object
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/steep/signature/validator.rb', line 200 def mixin_constraints(definition, mixin_ancestors, immediate_self_types:) # @type var relations: Array[[Subtyping::Relation[AST::Types::t], RBS::Definition::Ancestor::Instance]] relations = [] self_type = checker.factory.type(definition.self_type) if immediate_self_types && !immediate_self_types.empty? # @type var sts: Array[AST::Types::t] sts = immediate_self_types.map {|st| ancestor_to_type(st) } self_type = AST::Types::Intersection.build(types: sts.push(self_type)) end mixin_ancestors.each do |ancestor| args = ancestor.args.map {|type| checker.factory.type(type) } ancestor_ancestors = builder.ancestor_builder.one_instance_ancestors(ancestor.name) ancestor_ancestors.self_types or raise ancestor_ancestors.params or raise self_constraints = ancestor_ancestors.self_types.map do |self_ancestor| s = Interface::Substitution.build(ancestor_ancestors.params, args) ancestor_to_type(self_ancestor).subst(s) end self_constraints.each do |constraint| relations << [ Subtyping::Relation.new(sub_type: self_type, super_type: constraint), ancestor ] end end relations end |
#no_error? ⇒ Boolean
31 32 33 |
# File 'lib/steep/signature/validator.rb', line 31 def no_error? @errors.empty? end |
#push_context(self_type: , class_type: , instance_type: ) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/steep/signature/validator.rb', line 16 def push_context(self_type: latest_context[0], class_type: latest_context[1], instance_type: latest_context[2]) @context.push([self_type, class_type, instance_type]) yield ensure @context.pop end |
#rescue_validation_errors(type_name = nil) ⇒ Object
708 709 710 711 712 |
# File 'lib/steep/signature/validator.rb', line 708 def rescue_validation_errors(type_name = nil) yield rescue RBS::BaseError => exn @errors << Diagnostic::Signature.from_rbs_error(exn, factory: factory) end |
#type_name_resolver ⇒ Object
51 52 53 |
# File 'lib/steep/signature/validator.rb', line 51 def type_name_resolver @type_name_resolver ||= RBS::Resolver::TypeNameResolver.build(env) end |
#validate ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/steep/signature/validator.rb', line 63 def validate @errors = [] validate_decl validate_const validate_global validate_alias end |
#validate_alias ⇒ Object
702 703 704 705 706 |
# File 'lib/steep/signature/validator.rb', line 702 def validate_alias env.type_alias_decls.each do |name, entry| validate_one_alias(name, entry) end end |
#validate_ancestor_application(name, ancestor) ⇒ Object
528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'lib/steep/signature/validator.rb', line 528 def validate_ancestor_application(name, ancestor) unless ancestor.args.empty? definition = case when ancestor.name.class? builder.build_instance(ancestor.name) when ancestor.name.interface? builder.build_interface(ancestor.name) else raise end location = case ancestor.source when :super primary_decl = env.class_decls.fetch(name).primary_decl unless primary_decl.is_a?(RBS::AST::Declarations::Class) || primary_decl.is_a?(RBS::AST::Ruby::Declarations::ClassDecl) raise end if super_class = primary_decl.super_class super_class.location else # Implicit super class (Object): this can be skipped in fact... primary_decl.location&.aref(:name) end else ancestor.source&.location end validate_type_application_constraints( ancestor.name, definition.type_params_decl, ancestor.args, location: location ) ancestor.args.each do |arg| validate_type(arg) end end end |
#validate_const ⇒ Object
627 628 629 630 631 |
# File 'lib/steep/signature/validator.rb', line 627 def validate_const env.constant_decls.each do |name, entry| validate_one_constant(name, entry) end end |
#validate_decl ⇒ Object
613 614 615 616 617 618 619 620 621 622 623 624 625 |
# File 'lib/steep/signature/validator.rb', line 613 def validate_decl env.class_decls.each_key do |name| validate_one_class(name) end env.class_alias_decls.each do |name, entry| validate_one_class_alias(name, entry) end env.interface_decls.each_key do |name| validate_one_interface(name) end end |
#validate_definition_type(definition) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 |
# File 'lib/steep/signature/validator.rb', line 260 def validate_definition_type(definition) each_method_type(definition) do |method_type| upper_bounds = method_type.type_params.each.with_object({}) do |param, hash| #$ Hash[Symbol, AST::Types::t?] hash[param.name] = factory.type_opt(param.upper_bound_type) end checker.push_variable_bounds(upper_bounds) do method_type.each_type do |type| validate_type(type) end end end each_variable_type(definition) do |type| validate_type(type) end end |
#validate_global ⇒ Object
641 642 643 644 645 |
# File 'lib/steep/signature/validator.rb', line 641 def validate_global env.global_decls.each do |name, entry| validate_one_global(name, entry) end end |
#validate_one_alias(name, entry = env.type_alias_decls.fetch(name)) ⇒ Object
654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 |
# File 'lib/steep/signature/validator.rb', line 654 def validate_one_alias(name, entry = env.type_alias_decls.fetch(name)) inner_most_outer_module_name = entry.context&.last if inner_most_outer_module_name inner_most_outer_module = env.module_class_entry(inner_most_outer_module_name, normalized: true) if inner_most_outer_module class_type = AST::Types::Name::Singleton.new(name: inner_most_outer_module.name) instance_type = AST::Types::Name::Instance.new( name: inner_most_outer_module.name, args: inner_most_outer_module.type_params.map { AST::Types::Any.instance() }, ) end end push_context(class_type: class_type, instance_type: instance_type, self_type: nil) do rescue_validation_errors(name) do Steep.logger.debug "Validating alias `#{name}`..." unless name.namespace.empty? outer = name.namespace.to_type_name builder.validate_type_name(outer, entry.decl.location&.aref(:name)) end validate_type_params(name, entry.decl.type_params) upper_bounds = entry.decl.type_params.each.with_object({}) do |param, bounds| #$ Hash[Symbol, AST::Types::t?] bounds[param.name] = factory.type_opt(param.upper_bound_type) end validator.validate_type_alias(entry: entry) do |type| checker.push_variable_bounds(upper_bounds) do validate_type(entry.decl.type) end end end end end |
#validate_one_class(name) ⇒ Object
517 518 519 520 521 522 523 524 525 526 |
# File 'lib/steep/signature/validator.rb', line 517 def validate_one_class(name) entry = env.constant_entry(name) case entry when RBS::Environment::ClassEntry, RBS::Environment::ModuleEntry validate_one_class_decl(name, entry) when RBS::Environment::ClassAliasEntry, RBS::Environment::ModuleAliasEntry validate_one_class_alias(name, entry) end end |
#validate_one_class_alias(name, entry) ⇒ Object
692 693 694 695 696 697 698 699 700 |
# File 'lib/steep/signature/validator.rb', line 692 def validate_one_class_alias(name, entry) rescue_validation_errors(name) do Steep.logger.debug "Validating class/module alias `#{name}`..." validator.validate_class_alias(entry: entry) if location = entry.decl.location validate_type_name_deprecation(entry.decl.old_name, location[:old_name]) end end end |
#validate_one_class_decl(name, entry) ⇒ Object
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 |
# File 'lib/steep/signature/validator.rb', line 314 def validate_one_class_decl(name, entry) rescue_validation_errors(name) do Steep.logger.debug { "Validating class definition `#{name}`..." } class_type = AST::Types::Name::Singleton.new(name: name) instance_type = AST::Types::Name::Instance.new( name: name, args: entry.type_params.map { AST::Types::Any.instance() } ) entry.each_decl do |decl| if decl.is_a?(RBS::AST::Declarations::Base) unless AnnotationsHelper.deprecated_annotation?(decl.annotations) if location = decl.location validate_type_name_deprecation(name, location[:name]) end end end end Steep.logger.tagged "#{name}" do builder.build_instance(name).tap do |definition| upper_bounds = definition.type_params_decl.each.with_object({}) do |param, bounds| #$ Hash[Symbol, AST::Types::t?] bounds[param.name] = factory.type_opt(param.upper_bound_type) end self_type = AST::Types::Name::Instance.new( name: name, args: entry.type_params.map { AST::Types::Var.new(name: _1.name) } ) push_context(self_type: self_type, class_type: class_type, instance_type: instance_type) do checker.push_variable_bounds(upper_bounds) do definition.instance_variables.each do |name, var| if parent = var.parent_variable var_type = checker.factory.type(var.type) parent_type = checker.factory.type(parent.type) relation = Subtyping::Relation.new(sub_type: var_type, super_type: parent_type) result1 = checker.check(relation, self_type: nil, instance_type: nil, class_type: nil, constraints: Subtyping::Constraints.empty) result2 = checker.check(relation.flip, self_type: nil, instance_type: nil, class_type: nil, constraints: Subtyping::Constraints.empty) unless result1.success? and result2.success? @errors << Diagnostic::Signature::InstanceVariableTypeError.new( name: name, location: var.type.location, var_type: var_type, parent_type: parent_type ) end end end ancestors = builder.ancestor_builder.one_instance_ancestors(name) mixin_constraints(definition, ancestors.included_modules || raise, immediate_self_types: ancestors.self_types).each do |relation, ancestor| checker.check( relation, self_type: AST::Types::Self.instance, instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance, constraints: Subtyping::Constraints.empty ).else do raise if ancestor.source.is_a?(Symbol) @errors << Diagnostic::Signature::ModuleSelfTypeError.new( name: name, location: ancestor.source&.location || raise, ancestor: ancestor, result: _1 ) end end ancestors.each_ancestor do |ancestor| case ancestor when RBS::Definition::Ancestor::Instance validate_ancestor_application(name, ancestor) location = case ancestor.source when :super if (primary_decl = entry.primary_decl).is_a?(RBS::AST::Declarations::Class) primary_decl.super_class&.location end when nil # skip else ancestor.source.location end if location validate_type_name_deprecation(ancestor.name, location) end end end validate_definition_type(definition) end end end builder.build_singleton(name).tap do |definition| entry = case definition.entry when RBS::Environment::ClassEntry, RBS::Environment::ModuleEntry definition.entry else raise end push_context(self_type: class_type, class_type: class_type, instance_type: instance_type) do definition.instance_variables.each do |name, var| if parent = var.parent_variable var_type = checker.factory.type(var.type) parent_type = checker.factory.type(parent.type) relation = Subtyping::Relation.new(sub_type: var_type, super_type: parent_type) result1 = checker.check( relation, self_type: AST::Types::Self.instance, instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance, constraints: Subtyping::Constraints.empty ) result2 = checker.check( relation.flip, self_type: AST::Types::Self.instance, instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance, constraints: Subtyping::Constraints.empty ) unless result1.success? and result2.success? @errors << Diagnostic::Signature::InstanceVariableTypeError.new( name: name, location: var.type.location, var_type: var_type, parent_type: parent_type ) end end end definition.class_variables.each do |name, var| if var.declared_in == definition.type_name if (parent = var.parent_variable) && var.declared_in != parent.declared_in members = entry.each_decl.flat_map do |decl| case decl when RBS::AST::Declarations::Class, RBS::AST::Declarations::Module decl.members end end class_var = members.find do |member| member.is_a?(RBS::AST::Members::ClassVariable) && member.name == name end if class_var loc = class_var.location #: RBS::Location[untyped, untyped]? @errors << Diagnostic::Signature::ClassVariableDuplicationError.new( class_name: definition.type_name, other_class_name: parent.declared_in, variable_name: name, location: loc&.[](:name) || raise ) end end end end ancestors = builder.ancestor_builder.one_singleton_ancestors(name) ancestors.extended_modules or raise mixin_constraints(definition, ancestors.extended_modules, immediate_self_types: ancestors.self_types).each do |relation, ancestor| checker.check( relation, self_type: AST::Types::Self.instance , instance_type: AST::Types::Instance.instance, class_type: AST::Types::Class.instance, constraints: Subtyping::Constraints.empty ).else do raise if ancestor.source.is_a?(Symbol) @errors << Diagnostic::Signature::ModuleSelfTypeError.new( name: name, location: ancestor.source&.location || raise, ancestor: ancestor, result: _1 ) end end ancestors.each_ancestor do |ancestor| case ancestor when RBS::Definition::Ancestor::Instance validate_ancestor_application(name, ancestor) end end validate_definition_type(definition) end end validate_type_params(name, entry.type_params) end end end |
#validate_one_constant(name, entry) ⇒ Object
633 634 635 636 637 638 639 |
# File 'lib/steep/signature/validator.rb', line 633 def validate_one_constant(name, entry) rescue_validation_errors do Steep.logger.debug "Validating constant `#{name}`..." builder.ensure_namespace!(name.namespace, location: entry.decl.location) validate_type entry.decl.type end end |
#validate_one_global(name, entry) ⇒ Object
647 648 649 650 651 652 |
# File 'lib/steep/signature/validator.rb', line 647 def validate_one_global(name, entry) rescue_validation_errors do Steep.logger.debug "Validating global `#{name}`..." validate_type entry.decl.type end end |
#validate_one_interface(name) ⇒ Object
570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 |
# File 'lib/steep/signature/validator.rb', line 570 def validate_one_interface(name) rescue_validation_errors(name) do Steep.logger.debug "Validating interface `#{name}`..." Steep.logger.tagged "#{name}" do definition = builder.build_interface(name) validate_type_params(name, definition.type_params_decl) upper_bounds = definition.type_params_decl.each.with_object({}) do |param, bounds| #$ Hash[Symbol, AST::Types::t?] bounds[param.name] = factory.type_opt(param.upper_bound_type) end self_type = AST::Types::Name::Interface.new( name: name, args: definition.type_params.map { AST::Types::Var.new(name: _1) } ) push_context(self_type: self_type, class_type: nil, instance_type: nil) do checker.push_variable_bounds(upper_bounds) do validate_definition_type(definition) ancestors = builder.ancestor_builder.one_interface_ancestors(name) ancestors.each_ancestor do |ancestor| case ancestor when RBS::Definition::Ancestor::Instance # Interface ancestor cannot be other than Interface ancestor.source.is_a?(Symbol) and raise defn = builder.build_interface(ancestor.name) validate_type_application_constraints( ancestor.name, defn.type_params_decl, ancestor.args, location: ancestor.source&.location || raise ) end end end end end end end |
#validate_type(type) ⇒ Object
149 150 151 152 153 154 |
# File 'lib/steep/signature/validator.rb', line 149 def validate_type(type) Steep.logger.debug { "#{Location.to_string type.location}: Validating #{type}..." } validator.validate_type(type, context: nil) validate_type_0(type) end |
#validate_type_0(type) ⇒ Object
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/steep/signature/validator.rb', line 156 def validate_type_0(type) validate_type_application(type) case type when RBS::Types::ClassInstance, RBS::Types::Interface, RBS::Types::ClassSingleton, RBS::Types::Alias type_name = type.name if type.location location = type.location[:name] end end if type_name && location validate_type_name_deprecation(type_name, location) end type.each_type do |child| validate_type_0(child) end end |
#validate_type_application(type) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/steep/signature/validator.rb', line 116 def validate_type_application(type) name, type_params, type_args = case type when RBS::Types::ClassInstance [ type.name, builder.build_instance(type.name).type_params_decl, type.args ] when RBS::Types::Interface [ type.name, builder.build_interface(type.name).type_params_decl, type.args ] when RBS::Types::Alias type_name = env.normalize_type_name?(type.name) or return entry = env.type_alias_decls.fetch(type_name) [ type_name, entry.decl.type_params, type.args ] end if name && type_params && type_args if !type_params.empty? && !type_args.empty? validate_type_application_constraints(name, type_params, type_args, location: type.location) end end end |
#validate_type_application_constraints(type_name, type_params, type_args, location:) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/steep/signature/validator.rb', line 72 def validate_type_application_constraints(type_name, type_params, type_args, location:) if type_params.size == type_args.size subst = Interface::Substitution.build( type_params.map(&:name), type_args.map {|type| factory.type(type) } ) type_params.zip(type_args).each do |param, arg| arg or raise if param.upper_bound_type upper_bound_type = factory.type(param.upper_bound_type).subst(subst) arg_type = factory.type(arg) constraints = Subtyping::Constraints.empty self_type, class_type, instance_type = latest_context checker.check( Subtyping::Relation.new(sub_type: arg_type, super_type: upper_bound_type), self_type: self_type, class_type: class_type, instance_type: instance_type, constraints: constraints ).else do |result| @errors << Diagnostic::Signature::UnsatisfiableTypeApplication.new( type_name: type_name, type_arg: arg_type, type_param: Interface::TypeParam.new( name: param.name, upper_bound: upper_bound_type, variance: param.variance, unchecked: param.unchecked?, default_type: factory.type_opt(param.default_type) ), result: result, location: location ) end end end end end |
#validate_type_name_deprecation(type_name, location) ⇒ Object
176 177 178 179 180 |
# File 'lib/steep/signature/validator.rb', line 176 def validate_type_name_deprecation(type_name, location) if (_, = AnnotationsHelper.deprecated_type_name?(type_name, env)) @errors << Diagnostic::Signature::DeprecatedTypeName.new(type_name, , location: location) end end |
#validate_type_params(type_name, type_params) ⇒ Object
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
# File 'lib/steep/signature/validator.rb', line 278 def validate_type_params(type_name, type_params) if error_type_params = RBS::AST::TypeParam.validate(type_params) error_type_params.each do |type_param| default_type = type_param.default_type or raise @errors << Diagnostic::Signature::TypeParamDefaultReferenceError.new(type_param, location: default_type.location) end end upper_bounds = type_params.each.with_object({}) do |param, bounds| #$ Hash[Symbol, AST::Types::t?] bounds[param.name] = factory.type_opt(param.upper_bound_type) end checker.push_variable_bounds(upper_bounds) do type_params.each do |type_param| param = checker.factory.type_param(type_param) validate_type(type_param.upper_bound_type) if type_param.upper_bound_type validate_type(type_param.default_type) if type_param.default_type default_type = param.default_type or next upper_bound = param.upper_bound or next relation = Subtyping::Relation.new(sub_type: default_type, super_type: upper_bound) result = checker.check(relation, self_type: nil, instance_type: nil, class_type: nil, constraints: Subtyping::Constraints.empty) if result.failure? @errors << Diagnostic::Signature::UnsatisfiableGenericsDefaultType.new( type_param.name, result, location: (type_param.default_type || raise).location ) end end end end |
#validator ⇒ Object
55 56 57 |
# File 'lib/steep/signature/validator.rb', line 55 def validator @validator ||= RBS::Validator.new(env: env, resolver: type_name_resolver) end |