Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
a5a0bc6c
Commit
a5a0bc6c
authored
Apr 25, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow a parameter's default to be set explicitly to null.
Fixes #363.
parent
7aca59a9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
29 additions
and
2 deletions
+29
-2
node-translator.c++
c++/src/capnp/compiler/node-translator.c++
+22
-2
test.capnp
c++/src/capnp/test.capnp
+2
-0
errors.capnp.nobuild
c++/src/capnp/testdata/errors.capnp.nobuild
+4
-0
errors.txt
c++/src/capnp/testdata/errors.txt
+1
-0
No files found.
c++/src/capnp/compiler/node-translator.c++
View file @
a5a0bc6c
...
...
@@ -2102,8 +2102,28 @@ private:
auto
typeBuilder
=
slot
.
initType
();
if
(
translator
.
compileType
(
member
.
fieldType
,
typeBuilder
,
implicitMethodParams
))
{
if
(
member
.
hasDefaultValue
)
{
translator
.
compileBootstrapValue
(
member
.
fieldDefaultValue
,
typeBuilder
,
slot
.
initDefaultValue
());
if
(
member
.
isParam
&&
member
.
fieldDefaultValue
.
isRelativeName
()
&&
member
.
fieldDefaultValue
.
getRelativeName
().
getValue
()
==
"null"
)
{
// special case: parameter set null
switch
(
typeBuilder
.
which
())
{
case
schema
:
:
Type
::
TEXT
:
case
schema
:
:
Type
::
DATA
:
case
schema
:
:
Type
::
LIST
:
case
schema
:
:
Type
::
STRUCT
:
case
schema
:
:
Type
::
INTERFACE
:
case
schema
:
:
Type
::
ANY_POINTER
:
break
;
default
:
errorReporter
.
addErrorOn
(
member
.
fieldDefaultValue
.
getRelativeName
(),
"Only pointer parameters can declare their default as 'null'."
);
break
;
}
translator
.
compileDefaultDefaultValue
(
typeBuilder
,
slot
.
initDefaultValue
());
}
else
{
translator
.
compileBootstrapValue
(
member
.
fieldDefaultValue
,
typeBuilder
,
slot
.
initDefaultValue
());
}
slot
.
setHadExplicitDefault
(
true
);
}
else
{
translator
.
compileDefaultDefaultValue
(
typeBuilder
,
slot
.
initDefaultValue
());
...
...
c++/src/capnp/test.capnp
View file @
a5a0bc6c
...
...
@@ -840,6 +840,8 @@ interface TestMoreStuff extends(TestCallOrder) {
methodWithDefaults @8 (a :Text, b :UInt32 = 123, c :Text = "foo") -> (d :Text, e :Text = "bar");
methodWithNullDefault @12 (a :Text, b :TestInterface = null);
getHandle @9 () -> (handle :TestHandle);
# Get a new handle. Tests have an out-of-band way to check the current number of live handles, so
# this can be used to test garbage collection.
...
...
c++/src/capnp/testdata/errors.capnp.nobuild
View file @
a5a0bc6c
...
...
@@ -155,3 +155,7 @@ const embedNoSuchFile :Data = embed "no-such-file";
using Baz = import "nosuchfile-unused.capnp".Baz;
# Check that an import in an unused `using` still reports error.
interface TestInterface {
foo @0 (a :UInt32 = null);
}
c++/src/capnp/testdata/errors.txt
View file @
a5a0bc6c
...
...
@@ -56,4 +56,5 @@ 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.
file:153:30-44: error: Embeds can only be used when Text, Data, or a struct is expected.
file:154:37-51: error: Couldn't read file for embed: no-such-file
file:160:23-27: error: Only pointer parameters can declare their default as 'null'.
file:156:20-45: error: Import failed: nosuchfile-unused.capnp
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment