Skip to content

Commit

Permalink
Two bug fixes:
Browse files Browse the repository at this point in the history
1. Be sure to initialize new objects with their GUIDs.
2. Be sure to record that loaded objects are loaded.
  • Loading branch information
mcoblenz committed Sep 4, 2019
1 parent cd2cc85 commit 671b08b
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/main/scala/edu/cmu/cs/obsidian/codegen/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2270,7 +2270,8 @@ class CodeGen (val target: Target, table: SymbolTable) {
JExpr._null(), reflectionClassLookupExceptions)
tempArchive
} else {
block.assign(assignTo, JExpr._new(resolveType(typ, table))) // If not a generic type
val newObj = withArgs(JExpr._new(resolveType(typ, table)), constructorParams)
block.assign(assignTo, newObj) // If not a generic type
archive.invoke("getObj")
}

Expand Down Expand Up @@ -2304,7 +2305,7 @@ class CodeGen (val target: Target, table: SymbolTable) {
// TODO
/* generate another method that takes the actual archive type
* so we don't have to uselessly convert to bytes here */
body.decl(model.ref("String"), javaFieldName + "ID",
val guidVar = body.decl(model.ref("String"), javaFieldName + "ID",
archive.invoke(getterNameForField(javaFieldName)))
body.decl(javaFieldType, javaFieldName + "Val",
JExpr.cast(javaFieldType,
Expand All @@ -2323,7 +2324,7 @@ class CodeGen (val target: Target, table: SymbolTable) {
constructNew(translationContext, field.typ, inContract, archive,
checkForObj._else(), fieldVar, fieldVar,
List(javaStringType().dotclass()),
List(JExpr.ref(javaFieldName + "ID")))
List(guidVar))

// We also need to put this thing in the map of loaded objects,
// so if someone else references it later, we get the same reference.
Expand Down Expand Up @@ -2507,6 +2508,8 @@ class CodeGen (val target: Target, table: SymbolTable) {
val javaFieldVar = newClass.fields().get(field.name)
generateFieldInitializer(field, javaFieldVar, cond._then(), archive, translationContext, contract)
}

fromArchiveBody.assign(JExpr.ref(loadedFieldName), JExpr.lit(true))
}

private def refGenericParam(param: GenericType) = {
Expand Down

0 comments on commit 671b08b

Please sign in to comment.