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

Dyno: a couple more minor fixes #26683

Merged
merged 3 commits into from
Feb 10, 2025
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions frontend/lib/resolution/Resolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5402,6 +5402,13 @@ getDecoratedClassForNew(Context* context, const New* node,

switch (node->management()) {
case New::DEFAULT_MANAGEMENT:
// Management might've been provided for us already; otherwise
// fall back to the default: 'owned'.
if (!classType->decorator().isUnknownManagement())
break;

// Fall through to 'owned' management.

case New::OWNED:
decorator = ClassTypeDecorator(ClassTypeDecorator::MANAGED);
manager = AnyOwnedType::get(context);
Expand Down
14 changes: 9 additions & 5 deletions frontend/lib/resolution/default-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -946,17 +946,21 @@ generateRecordBinaryOperator(Context* context, UniqueString op,

static const TypedFnSignature*
generateRecordAssignment(Context* context, const CompositeType* lhsType) {
// rhs used to be 'maybe const' but now 'const' is default.
//
// TODO: it's possible that we need to compute the dyno equivalent of
// FLAG_COPY_MUTATES to get the right constness here.
return generateRecordBinaryOperator(context, USTR("="), lhsType,
/*this*/ QualifiedType::CONST_REF,
/*lhs*/ QualifiedType::CONST_REF,
/*rhs*/ QualifiedType::CONST_REF);
/*this*/ QualifiedType::TYPE,
/*lhs*/ QualifiedType::REF,
/*rhs*/ QualifiedType::CONST_REF );
}

static const TypedFnSignature*
generateRecordComparison(Context* context, const CompositeType* lhsType) {
return generateRecordBinaryOperator(context, USTR("=="), lhsType,
/*this*/ QualifiedType::REF,
/*lhs*/ QualifiedType::REF,
/*this*/ QualifiedType::TYPE,
/*lhs*/ QualifiedType::CONST_REF,
/*rhs*/ QualifiedType::CONST_REF);
}

Expand Down
18 changes: 18 additions & 0 deletions frontend/test/resolution/testNew.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1040,6 +1040,23 @@ static void testUserGenericNew() {
assert(guard.realizeErrors() == 1);
}

static void testExplicitManagementNew() {
auto ctx = buildStdContext();
ErrorGuard guard(ctx);

auto var = resolveTypeOfXInit(ctx,
R"""(
class C{}
proc getType() type do return unmanaged C;
var x = new (getType())();
)""");

assert(var.type()->isClassType());
assert(var.type()->toClassType()->decorator().isUnmanaged());
}


int main() {
testEmptyRecordUserInit();
Expand All @@ -1056,6 +1073,7 @@ int main() {
testCompilerGeneratedGenericNewClass();
testSimpleUserGenericNew();
testUserGenericNew();
testExplicitManagementNew();

return 0;
}
Expand Down
10 changes: 6 additions & 4 deletions frontend/test/resolution/testOperatorOverloads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,10 +230,12 @@ static void test4() {
var x : int;
}
var a : R;
var b : R;
var x = a == b;
proc foo() {
const a : R;
const b : R;
return a == b;
}
var x = foo();
)"""";

QualifiedType initType = resolveTypeOfXInit(context, program);
Expand Down