Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #3278 fixed complex type handling to be consistent with non-comp… #3282

Merged
merged 1 commit into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 30 additions & 0 deletions examples/test/qore/misc/types.qtest
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const TestList = (1, 2, 3);

class TypeTest inherits QUnit::Test {
constructor() : QUnit::Test("TypeTest", "1.0") {
addTestCase("issue 3278", \issue3278());
addTestCase("issue 3210", \issue3210());
addTestCase("issue 3157", \issue3157());
addTestCase("issue 2980", \issue2980());
Expand All @@ -54,6 +55,35 @@ class TypeTest inherits QUnit::Test {
set_return_value(main());
}

issue3278() {
auto x = ();
{
hash h = map {$1: True}, x;
assertEq({}, h);
assertEq("hash", h.fullType());
}
{
hash<auto> h = map {$1: True}, x;
assertEq({}, h);
assertEq("hash<string, bool>", h.fullType());
}
/*
{
hash<string, bool> h = map {$1: True}, x;
assertEq({}, h);
assertEq("hash<string, bool>", h.fullType());
}
*/
/*
{
*list<int> x = ();
list<int> v = x;
assertEq((), v);
assertEq("list<int>", v.fullType());
}
*/
}

issue3210() {
{
Program p(PO_NEW_STYLE);
Expand Down
12 changes: 5 additions & 7 deletions lib/QoreAssignmentOperatorNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Qore Programming Language

Copyright (C) 2003 - 2018 Qore Technologies, s.r.o.
Copyright (C) 2003 - 2019 Qore Technologies, s.r.o.

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down Expand Up @@ -70,17 +70,15 @@ void QoreAssignmentOperatorNode::parseInitIntern(LocalVar* oflag, int pflag, int
ident = true;
}
res = QTI_IDENT;
}
else if (QoreTypeInfo::hasType(ti)) {
} else if (QoreTypeInfo::hasType(ti)) {
bool may_not_match = false;
bool may_need_filter = false;
res = QoreTypeInfo::parseAccepts(ti, r, may_not_match, may_need_filter);
// issue #2106 do not set the ident flag for any other type in case runtime types are more specific (complex) than parse types and require filtering
}
else
//printd(5, "QoreAssignmentOperatorNode::parseInitImpl() '%s' <- '%s' res: %d may_not_match: %d may_need_filter: %d ident: %d\n", QoreTypeInfo::getName(ti), QoreTypeInfo::getName(r), res, may_not_match, may_need_filter, ident);
} else {
res = QTI_AMBIGUOUS;

//printd(5, "QoreAssignmentOperatorNode::parseInitImpl() '%s' <- '%s' res: %d may_not_match: %d may_need_filter: %d ident: %d\n", QoreTypeInfo::getName(ti), QoreTypeInfo::getName(r), res, may_not_match, may_need_filter, ident);
}

if (getProgram()->getParseExceptionSink() && !res) {
QoreStringNode* edesc = new QoreStringNodeMaker("lvalue for %sassignment operator '%s' expects ", weak_assignment ? "weak " : "", weak_assignment ? ":=" : "=");
Expand Down
12 changes: 7 additions & 5 deletions lib/QoreTypeInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -545,11 +545,13 @@ const char* getBuiltinTypeName(qore_type_t type) {
return "<unknown type>";
}

// only called for complex hashes and lists
static qore_type_result_e match_type(const QoreTypeInfo* this_type, const QoreTypeInfo* that_type, bool& may_not_match, bool& may_need_filter) {
//printd(5, "QoreTypeSpec::match() '%s' <- '%s'\n", QoreTypeInfo::getName(u.ti), QoreTypeInfo::getName(t.u.ti));
//printd(5, "QoreTypeSpec::match() '%s' <- '%s'\n", QoreTypeInfo::getName(this_type), QoreTypeInfo::getName(that_type));
qore_type_result_e res = QoreTypeInfo::parseAccepts(this_type, that_type, may_not_match, may_need_filter);
if (may_not_match)
return QTI_NOT_EQUAL;
// with strict-types, may not match must be interpreted as no match
// however if we interpret "may not match" as "no match" here, then we introduce an incompatibility with
// non-complex types
// even if types are 100% compatible, if they are not equal, then we perform type folding
if (res == QTI_IDENT && !may_need_filter && !QoreTypeInfo::equal(this_type, that_type)) {
may_need_filter = true;
Expand Down Expand Up @@ -595,7 +597,7 @@ qore_type_result_e QoreTypeSpec::match(const QoreTypeSpec& t, bool& may_not_matc
return QTI_NOT_EQUAL;
}
case QTS_COMPLEXHASH: {
//printd(5, "QoreTypeSpec::match() t.typespec: %d '%s'\n", (int)t.typespec, QoreTypeInfo::getName(u.ti));
//printd(5, "QoreTypeSpec::match() %d: t.typespec: %d '%s'\n", typespec, (int)t.typespec, QoreTypeInfo::getName(u.ti));
switch (t.typespec) {
case QTS_COMPLEXHASH:
return match_type(u.ti, t.u.ti, may_not_match, may_need_filter);
Expand All @@ -616,7 +618,7 @@ qore_type_result_e QoreTypeSpec::match(const QoreTypeSpec& t, bool& may_not_matc
}
case QTS_COMPLEXSOFTLIST:
case QTS_COMPLEXLIST: {
//printd(5, "QoreTypeSpec::match() t.typespec: %d '%s'\n", (int)t.typespec, QoreTypeInfo::getName(u.ti));
//printd(5, "QoreTypeSpec::match() %d: t.typespec: %d '%s'\n", typespec, (int)t.typespec, QoreTypeInfo::getName(u.ti));
switch (t.typespec) {
case QTS_COMPLEXSOFTLIST:
case QTS_COMPLEXLIST:
Expand Down
4 changes: 3 additions & 1 deletion qlib/Util.qm
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,9 @@ string pass = get_random_string();
str += sprintf("%s exception: %s: %s: %s",
ex.type, get_ex_pos(ex), ex.err, ex.desc);
if (exists ex.arg) {
if (ex.arg.ex instanceof hash<ExceptionInfo>) {
if (ex.arg.ex instanceof hash<ExceptionInfo>
|| (ex.arg.ex.typeCode() == NT_STRING && ex.arg.desc.typeCode() == NT_STRING
&& ex.arg.callstack.typeCode() == NT_LIST)) {
if (ex.arg.size() > 1) {
str += sprintf(" (arg: %y)", ex.arg - "ex");
}
Expand Down