Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reword error message when including/inheriting generic type without type vars #10206

Merged
merged 1 commit into from
Jan 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spec/compiler/semantic/generic_class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ describe "Semantic: generic class" do
class Bar < Foo
end
),
"wrong number of type vars for Foo(T) (given 0, expected 1)"
"generic type arguments must be specified when inheriting Foo(T)"
end

%w(Object Value Reference Number Int Float Struct Class Proc Tuple Enum StaticArray Pointer).each do |type|
Expand Down
4 changes: 2 additions & 2 deletions spec/compiler/semantic/module_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe "Semantic: module" do
"wrong number of type vars for Foo(T, U) (given 1, expected 2)"
end

it "includes generic module but wrong number of arguments 2" do
it "errors if including generic module and not specifying type vars" do
assert_error "
module Foo(T)
end
Expand All @@ -110,7 +110,7 @@ describe "Semantic: module" do
include Foo
end
",
"wrong number of type vars for Foo(T) (given 0, expected 1)"
"generic type arguments must be specified when including Foo(T)"
end

it "includes generic module explicitly" do
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
find_root_generic_type_parameters: false).devirtualize
case superclass
when GenericClassType
node_superclass.raise "wrong number of type vars for #{superclass} (given 0, expected #{superclass.type_vars.size})"
node_superclass.raise "generic type arguments must be specified when inheriting #{superclass}"
when NonGenericClassType, GenericClassInstanceType
if superclass == @program.enum
node_superclass.raise "can't inherit Enum. Use the enum keyword to define enums"
Expand Down Expand Up @@ -980,7 +980,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
type = lookup_type(node_name)
case type
when GenericModuleType
node.raise "wrong number of type vars for #{type} (given 0, expected #{type.type_vars.size})"
node.raise "generic type arguments must be specified when including #{type}"
when .module?
# OK
else
Expand Down