@@ -560,6 +560,28 @@ sealed class Type(val constraints: List<ConstraintExpr> = listOf()) {
560560 override fun withTypeArguments (arguments : List <Type >): Class =
561561 Reference (ctx, arguments, constraints)
562562
563+ // enforce restrictions! cannot reference:
564+ // - external or local properties
565+ // - properties of Listing or Mapping
566+ // - Dynamic.default
567+ // - properties of any external class
568+ // - any Module.output
569+ private fun isViable (
570+ prop : PklClassProperty ,
571+ type : Type ,
572+ base : PklBaseModule ,
573+ context : PklProject ? ,
574+ ): Boolean =
575+ ! (prop.isExternal ||
576+ prop.isLocal ||
577+ (type as ? Class )?.let {
578+ it == base.listingType ||
579+ it == base.mappingType ||
580+ (it == base.dynamicType && prop.name == " default" ) ||
581+ it.ctx.isExternal
582+ } ? : false ||
583+ (type.isSubtypeOf(base.moduleType, base, context) && prop.name == " output" ))
584+
563585 override fun visitMembers (
564586 isProperty : Boolean ,
565587 allowClasses : Boolean ,
@@ -583,9 +605,9 @@ sealed class Type(val constraints: List<ConstraintExpr> = listOf()) {
583605 var isUnknown = false
584606 val candidates = mutableSetOf<PklType >()
585607
586- walkCandidates(referent, base, context) { _ , properties ->
608+ walkCandidates(referent, base, context) { type , properties ->
587609 for (prop in properties) {
588- if (! (prop.isExternal || prop.isLocal ) && prop.name == visitor.exactName) {
610+ if (isViable (prop, type, base, context ) && prop.name == visitor.exactName) {
589611 val propType = prop.type ? : PklFakeUnknownTypeImpl (ctx.project)
590612 if (propType is PklUnknownType ) {
591613 isUnknown = true
@@ -608,9 +630,9 @@ sealed class Type(val constraints: List<ConstraintExpr> = listOf()) {
608630 }
609631 else -> {
610632 val propertyCandidates = mutableMapOf<String , MutableSet <PklType >>()
611- walkCandidates(referent, base, context) { _ , properties ->
633+ walkCandidates(referent, base, context) { type , properties ->
612634 for (prop in properties) {
613- if (! (prop.isExternal || prop.isLocal )) {
635+ if (isViable (prop, type, base, context )) {
614636 propertyCandidates
615637 .getOrPut(prop.name) { mutableSetOf () }
616638 .add(prop.type ? : PklFakeUnknownTypeImpl (ctx.project))
0 commit comments