Commit 286b749e authored by Kenton Varda's avatar Kenton Varda

Generics: Fix compiler error test and test for new errors.

parent 122e0619
......@@ -563,7 +563,7 @@ public:
//
// It is an error to call this when `getKind()` returns null.
BrandedDecl& getListParam();
kj::Maybe<BrandedDecl&> getListParam();
// Only if the kind is BUILTIN_LIST: Get the list's type parameter.
Resolver::ResolvedParameter asVariable();
......@@ -624,10 +624,14 @@ public:
errorReporter.addErrorOn(source, "Double-application of generic parameters.");
return nullptr;
} else if (params.size() > leafParamCount) {
errorReporter.addErrorOn(source, "Too many generic arguments.");
if (leafParamCount == 0) {
errorReporter.addErrorOn(source, "Declaration does not accept generic parameters.");
} else {
errorReporter.addErrorOn(source, "Too many generic parameters.");
}
return nullptr;
} else if (params.size() < leafParamCount) {
errorReporter.addErrorOn(source, "Not enough generic arguments.");
errorReporter.addErrorOn(source, "Not enough generic parameters.");
return nullptr;
} else {
if (genericType != Declaration::BUILTIN_LIST) {
......@@ -838,16 +842,18 @@ uint64_t NodeTranslator::BrandedDecl::getIdAndFillBrand(InitBrandFunc&& initBran
return body.get<Resolver::ResolvedDecl>().id;
}
NodeTranslator::BrandedDecl& NodeTranslator::BrandedDecl::getListParam() {
kj::Maybe<NodeTranslator::BrandedDecl&> NodeTranslator::BrandedDecl::getListParam() {
KJ_REQUIRE(body.is<Resolver::ResolvedDecl>());
auto& decl = body.get<Resolver::ResolvedDecl>();
KJ_REQUIRE(decl.kind == Declaration::BUILTIN_LIST);
auto params = KJ_ASSERT_NONNULL(brand->getParams(decl.id));
KJ_ASSERT(params.size() == 1);
return params[0];
if (params.size() != 1) {
return nullptr;
} else {
return params[0];
}
}
NodeTranslator::Resolver::ResolvedParameter NodeTranslator::BrandedDecl::asVariable() {
......@@ -880,7 +886,13 @@ bool NodeTranslator::BrandedDecl::compileAsType(
case Declaration::BUILTIN_LIST: {
auto elementType = target.initList().initElementType();
if (!getListParam().compileAsType(errorReporter, elementType)) {
KJ_IF_MAYBE(param, getListParam()) {
if (!param->compileAsType(errorReporter, elementType)) {
return false;
}
} else {
addError(errorReporter, "'List' requires exactly one parameter.");
return false;
}
......@@ -1230,8 +1242,8 @@ kj::Maybe<NodeTranslator::BrandedDecl> NodeTranslator::BrandScope::compileDeclEx
return kj::mv(*memberDecl);
} else {
errorReporter.addErrorOn(name, kj::str(
'"', expressionString(member.getParent()),
"\" has no member named \"", name.getValue(), '"'));
"'", expressionString(member.getParent()),
"' has no member named '", name.getValue(), "'"));
return nullptr;
}
} else {
......
......@@ -655,7 +655,8 @@ CapnpParser::CapnpParser(Orphanage orphanageParam, ErrorReporter& errorReporterP
builder.setName(targetReader.getMember().getName());
} else {
errorReporter.addErrorOn(targetReader,
"'using' declaration without '=' must identify a named declaration.");
"'using' declaration without '=' must specify a named declaration from a "
"different scope.");
}
}
// no id, no annotations for using decl
......
......@@ -117,12 +117,12 @@ struct Foo {
undefinedAbsolute @47 : .NoSuch;
undefinedRelative @29 :NoSuch;
undefinedMember @30 :Foo.NoSuch;
defaultBadStructSyntax @48 :Foo = (123, bar = 456);
}
struct Bar {
x @3 :Text;
someGroup :group {
defaultMissingFieldName @2 :Bar = (x = "abcd", 456);
defaultNoSuchField @0 :Bar = (nosuchfield = 123);
defaultGroupMismatch @1 :Bar = (someGroup = 123);
}
......@@ -139,3 +139,13 @@ enum DupEnumerants {
}
const recursive: UInt32 = .recursive;
struct Generic(T, U) {
}
struct UseGeneric {
tooFew @0 :Generic(Text);
tooMany @1 :Generic(Text, Data, List(Int32));
doubleBind @2 :Generic(Text, Data)(Data, Text);
primitiveBinding @3 :Generic(Text, Int32);
}
......@@ -2,8 +2,7 @@ file:74:30-32: error: As of Cap'n Proto v0.3, it is no longer necessary to assig
file:74:30-32: error: As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon for named unions, e.g. `foo :union {`.
file:79:23-25: error: As of Cap'n Proto v0.3, it is no longer necessary to assign numbers to unions. However, removing the number will break binary compatibility. If this is an old protocol and you need to retain compatibility, please add an exclamation point after the number to indicate that it is really needed, e.g. `foo @1! :union {`. If this is a new protocol or compatibility doesn't matter, just remove the @n entirely. Sorry for the inconvenience, and thanks for being an early adopter! :)
file:84:17-19: error: As of Cap'n Proto v0.3, the 'union' keyword should be prefixed with a colon for named unions, e.g. `foo :union {`.
file:121:38-41: error: Missing field name.
file:132:7-10: error: 'using' declaration without '=' must use a qualified path.
file:132:7-10: error: 'using' declaration without '=' must specify a named declaration from a different scope.
file:37:3-10: error: 'dupName' is already defined in this scope.
file:36:3-10: error: 'dupName' previously defined here.
file:52:5-12: error: 'dupName' is already defined in this scope.
......@@ -24,12 +23,13 @@ file:41:18-19: error: Skipped ordinal @3. Ordinals must be sequential with no h
file:69:15-17: error: Union ordinal, if specified, must be greater than no more than one of its member ordinals (i.e. there can only be one field retroactively unionized).
file:116:31-50: error: Import failed: noshuchfile.capnp
file:118:26-32: error: Not defined: NoSuch
file:119:28-34: error: No such member: NoSuch
file:119:28-34: error: 'Foo' has no member named 'NoSuch'
file:97:25-29: error: 'List' requires exactly one parameter.
file:98:30-48: error: 'List' requires exactly one parameter.
file:98:30-48: error: Too many generic parameters.
file:98:30-34: error: 'List' requires exactly one parameter.
file:99:23-39: error: 'List(AnyPointer)' is not supported.
file:100:17-24: error: 'notType' is not a type.
file:101:17-27: error: 'Foo' does not accept parameters.
file:101:17-27: error: Declaration does not accept generic parameters.
file:103:34-41: error: Integer value out of range.
file:104:37-38: error: Integer value out of range.
file:105:32-35: error: Type mismatch; expected Text.
......@@ -44,8 +44,13 @@ file:113:29-47: error: 'notFieldAnnotation' cannot be applied to this kind of de
file:114:33-48: error: 'fieldAnnotation' requires a value.
file:126:35-46: error: Struct has no field named 'nosuchfield'.
file:127:49-52: error: Type mismatch; expected group.
file:125:52-55: error: Missing field name.
file:136:3-10: error: 'dupName' is already defined in this scope.
file:135:3-10: error: 'dupName' previously defined here.
file:138:15-16: error: Duplicate ordinal number.
file:137:15-16: error: Ordinal @2 originally used here.
file:141:7-16: error: Declaration recursively depends on itself.
file:147:14-27: error: Not enough generic parameters.
file:148:15-47: error: Too many generic parameters.
file:149:18-49: error: Double-application of generic parameters.
file:150:38-43: error: Sorry, only pointer types can be used as generic parameters.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment