Commit 95ef55eb authored by Kevin Modzelewski's avatar Kevin Modzelewski

Throw a SyntaxError if you try to import from __future__

I guess there's actually a real __future__ module that contains
information in it about the special features you just enabled!
Until this change you would get that information, but not actually
enable any features.  The right behavior is to raise a SyntaxError
for all __future__ directives we don't support (which is all of them).

"import __future__" works if you want that...

I'm not sure that throwing a SyntaxError from the IRGenerator is safe,
since there are things that won't get cleaned up, but I guess
it's not that much worse than if it worked; and this SyntaxError will
typically kill the program anyway.
parent 82ff6f53
......@@ -1572,6 +1572,15 @@ private:
if (state == PARTIAL)
return;
if (node->module == "__future__") {
// TODO I'm not sure that it's safe to raise an exception here, since I think
// there will be things that end up not getting cleaned up.
// Then again, there are a huge number of things that don't get cleaned up even
// if an exception doesn't get thrown...
raiseSyntaxError("the __future__ module is not supported yet", node->lineno, node->col_offset,
irstate->getSourceInfo()->parent_module->fn, irstate->getLLVMFunction()->getName());
}
assert(node->level == 0);
llvm::Value* imported_v
......
......@@ -452,6 +452,11 @@ void addToSysArgv(const char* str);
std::string formatException(Box* e);
void printLastTraceback();
// Raise a SyntaxError that occurs at a specific location.
// The traceback given to the user will include this,
// even though the execution didn't actually arrive there.
void raiseSyntaxError(const char* msg, int lineno, int col_offset, const std::string& file, const std::string& func);
struct LineInfo {
public:
const int line, column;
......
......@@ -121,6 +121,19 @@ void raiseExc(Box* exc_obj) {
raiseRaw(exc_obj);
}
// Have a special helper function for syntax errors, since we want to include the location
// of the syntax error in the traceback, even though it is not part of the execution:
void raiseSyntaxError(const char* msg, int lineno, int col_offset, const std::string& file, const std::string& func) {
last_exc = exceptionNew2(SyntaxError, boxStrConstant(msg));
auto entries = getTracebackEntries();
last_tb = std::move(entries);
// TODO: leaks this!
last_tb.push_back(new LineInfo(lineno, col_offset, file, func));
raiseRaw(last_exc);
}
void printLastTraceback() {
fprintf(stderr, "Traceback (most recent call last):\n");
......
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