Skip to content

Commit

Permalink
check for explicit dependencies
Browse files Browse the repository at this point in the history
While determining whether to create a no-arg convenience
constructor, we check for both explicit (creatable) dependencies
in addition to unsatisfied sinks to avoid generating incompatible code
  • Loading branch information
davissuber authored and TonyTangAndroid committed Dec 11, 2023
1 parent 6a7863d commit dfb9036
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/main/kotlin/motif/compiler/ScopeImplFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ private constructor(private val env: XProcessingEnv, private val graph: Resolved
}

private fun alternateConstructor(): AlternateConstructor? {
if (getDependencyMethodData(scope).isNotEmpty()) {
if (getDependencyMethodData(scope).isNotEmpty() ||
!scope.dependencies?.methods.isNullOrEmpty()) {
return null
}
return AlternateConstructor(scope.dependenciesClassName)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
########################################################################
# #
# This file is auto-generated by running the Motif compiler tests and #
# serves a as validation of graph correctness. IntelliJ plugin tests #
# also rely on this file to ensure that the plugin graph understanding #
# is equivalent to the compiler's. #
# #
# - Do not edit manually. #
# - Commit changes to source control. #
# - Since this file is autogenerated, code review changes carefully to #
# ensure correctness. #
# #
########################################################################

-------
| Scope |
-------

==== Required ====

==== Provides ====

---- Scope | implicit ----
[ Required ]
[ Consumed By ]


Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) 2023 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package testcases.KT007_scope_factory_dependencies

import motif.Creatable

@motif.Scope
interface Scope : Creatable<Scope.Dependencies> {
// note the absence of string() accessor (e.g. sink) in this scope
interface Dependencies {
fun string(): String
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) 2023 Uber Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package testcases.KT007_scope_factory_dependencies;

import motif.ScopeFactory;
import org.jetbrains.annotations.NotNull;

public class Test {

public static void run() {
ScopeFactory.create(
Scope.class, new Scope.Dependencies() {
@NotNull
@Override
public String string() {
return "s";
}
}
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
-libraryjars <java.home>/jmods/java.base.jmod(!**.jar;!module-info.class)
-dontshrink
-keep class **Test {
public static void run();
}

-keepnames @motif.Scope interface *
-keepnames @motif.ScopeImpl class * {
<init>(...);
}

0 comments on commit dfb9036

Please sign in to comment.