C++ compiler error when trying to use `self.position()` and another iterator
Closed this issue · 1 comments
bbannier commented
I would have expected the following to work:
# foo.spicy
module foo;
public type X = unit {
var start: iterator<stream>;
on %init { self.start = self.input(); }
: (Y(self.start))[];
};
type Y = unit(start: iterator<stream>) {
y: uint8 { print self.position() - start; }
};
$ spicyc -j foo.spicy
/private/var/folders/ht/vtb0rkbd4ws15vx02xdb84zw0000gn/T/foo_3938bf4a0abadc65-b1279778a4c61f1.cc:573:45: error: invalid
operands to binary expression ('std::optional< ::hilti::rt::stream::SafeConstIterator>' and '::hilti::rt::stream::SafeCo
nstIterator')
::hilti::rt::print((*__self).__position - __self->__p_start, ::hilti::rt::Bool(true));
~~~~~~~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/_
_ios/fpos.h:61:11: note: candidate template ignored: could not match 'fpos' against 'optional'
streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) {
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/_
_iterator/reverse_iterator.h:296:1: note: candidate template ignored: could not match 'reverse_iterator' against 'optiona
l'
operator-(const reverse_iterator<_Iter1>& __x, const reverse_iterator<_Iter2>& __y)
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/_
_iterator/wrap_iter.h:245:6: note: candidate template ignored: could not match '__wrap_iter' against 'optional'
auto operator-(const __wrap_iter<_Iter1>& __x, const __wrap_iter<_Iter2>& __y) _NOEXCEPT
^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk/usr/include/c++/v1/_
_iterator/move_iterator.h:283:6: note: candidate template ignored: could not match 'move_iterator' against 'optional'
auto operator-(const move_iterator<_Iter1>& __x, const move_iterator<_Iter2>& __y)
^
/Users/bbannier/src/spicy/hilti/runtime/include/hilti/rt/3rdparty/SafeInt/SafeInt.hpp:6731:30: note: candidate template
ignored: could not match 'SafeInt<T, E>' against '::hilti::rt::stream::SafeConstIterator'
_CONSTEXPR14 SafeInt< T, E > operator -( U lhs, SafeInt< T, E > rhs ) SAFEINT_CPP_THROW
^
1 error generated.
[error] spicy-driver: JIT compilation failed
We should either do the expected for this code or reject it.