Skip to content

Commit 2d68c38

Browse files
authored
Report more "unexpected bare value" errors (#7887)
* Add failing test * Fix failing test * Add a test making sure that T.unsafe works to silence
1 parent b2da362 commit 2d68c38

File tree

2 files changed

+78
-6
lines changed

2 files changed

+78
-6
lines changed

core/types/types.cc

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -982,13 +982,12 @@ TypePtr Types::unwrapType(const GlobalState &gs, Loc loc, const TypePtr &tp) {
982982
unwrappedElems.emplace_back(unwrapType(gs, loc, elem));
983983
}
984984
return make_type<TupleType>(move(unwrappedElems));
985-
} else if (isa_type<NamedLiteralType>(tp) || isa_type<IntegerLiteralType>(tp) || isa_type<FloatLiteralType>(tp)) {
986-
if (auto e = gs.beginError(loc, errors::Infer::BareTypeUsage)) {
987-
e.setHeader("Unexpected bare `{}` value found in type position", tp.show(gs));
988-
}
989-
return Types::untypedUntracked();
990985
}
991-
return tp;
986+
987+
if (auto e = gs.beginError(loc, errors::Infer::BareTypeUsage)) {
988+
e.setHeader("Unexpected bare `{}` value found in type position", tp.show(gs));
989+
}
990+
return Types::untypedUntracked();
992991
}
993992

994993
// This method is actually special: not only is it called from dispatchCall in calls.cc, it's
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# typed: true
2+
3+
class A
4+
extend T::Sig
5+
sig do
6+
type_parameters(:U)
7+
.params(x: T.type_parameter(:U))
8+
.void
9+
end
10+
def f1(x)
11+
T.reveal_type(x) # error: `T.type_parameter(:U) (of A#f1)`
12+
13+
type = T::Array[x]
14+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
15+
T.reveal_type(type) # error: `Runtime object representing type: T::Array[T.untyped]`
16+
17+
type = T.class_of(x)
18+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
19+
T.reveal_type(type) # error: `Runtime object representing type: T.untyped`
20+
21+
type = T.any(x, x)
22+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
23+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
24+
T.reveal_type(type) # error: `Runtime object representing type: T.untyped`
25+
26+
type = T.all(x, x)
27+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
28+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
29+
T.reveal_type(type) # error: `Runtime object representing type: T.untyped`
30+
31+
type = T.nilable(x)
32+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
33+
T.reveal_type(type) # error: `Runtime object representing type: T.untyped`
34+
35+
type = T.proc.params(arg0: x).void
36+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
37+
T.reveal_type(type) # error: `Runtime object representing type: T.proc.params(arg0: T.untyped).void`
38+
39+
type = T.proc.returns(x)
40+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f1)` value found in type position
41+
T.reveal_type(type) # error: `Runtime object representing type: T.proc.returns(T.untyped)`
42+
end
43+
44+
sig do
45+
type_parameters(:U)
46+
.params(x: T.type_parameter(:U))
47+
.void
48+
end
49+
def f2(x)
50+
T.reveal_type(x) # error: `T.type_parameter(:U) (of A#f2)`
51+
f = T.let(
52+
-> (x) {
53+
T.reveal_type(x) # error: `T.untyped`
54+
},
55+
T.proc.params(arg0: x).void
56+
# ^ error: Unsupported type syntax
57+
# ^ error: Unexpected bare `T.type_parameter(:U) (of A#f2)` value found in type position
58+
)
59+
T.reveal_type(f) # error: `T.proc.params(arg0: T.untyped).void`
60+
end
61+
62+
sig do
63+
type_parameters(:U)
64+
.params(type: T::Types::Base)
65+
.void
66+
end
67+
def f3(type)
68+
T.nilable(type)
69+
# ^^^^ error: Unexpected bare `T::Types::Base` value found in type position
70+
T.nilable(T.unsafe(type))
71+
end
72+
end
73+

0 commit comments

Comments
 (0)