Skip to content

feat: fix type check for FilteredAdapter using is operator#67

Merged
nomeguy merged 2 commits into
masterfrom
copilot/fix-adapter-type-check
Nov 18, 2025
Merged

feat: fix type check for FilteredAdapter using is operator#67
nomeguy merged 2 commits into
masterfrom
copilot/fix-adapter-type-check

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 18, 2025

The type check adapter.runtimeType == FilteredAdapter fails because FilteredAdapter is abstract—runtime types are concrete implementations like DefaultFilteredAdapter.

Changes

  • loadFilteredPolicy() (L179): adapter.runtimeType == FilteredAdapteradapter is FilteredAdapter
  • isFiltered() (L198): adapter.runtimeType == FilteredAdapteradapter is FilteredAdapter
// Before
if (adapter.runtimeType == FilteredAdapter) {
  filteredAdapter = (adapter as FilteredAdapter);
}

// After  
if (adapter is FilteredAdapter) {
  filteredAdapter = (adapter as FilteredAdapter);
}
Original prompt

This section details on the original issue you should resolve

<issue_title>wrong type check of adapter</issue_title>
<issue_description>In core_enforcer.dart, the type of the adapter is checked using adapter.runtimeType == FilteredAdapter, which would expect an exact match of FilteredAdapter, however FilteredAdapter is an abstract class so this will never evaluate to true.

This should be changed to: adapter is FilteredAdapter

Needs to be changed in two places:

https://github.com/casbin/dart-casbin/blob/9c72f3f5839d8cfbb456543a81891dc8c8556137/lib/src/core_enforcer.dart#L179

https://github.com/casbin/dart-casbin/blob/9c72f3f5839d8cfbb456543a81891dc8c8556137/lib/src/core_enforcer.dart#L198</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@nomeguy nomeguy marked this pull request as ready for review November 18, 2025 15:13
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

- Changed line 179: adapter.runtimeType == FilteredAdapter to adapter is FilteredAdapter
- Changed line 198: adapter.runtimeType == FilteredAdapter to adapter is FilteredAdapter

The previous check would never work since FilteredAdapter is abstract and runtime type would be a concrete implementation like DefaultFilteredAdapter.

Co-authored-by: nomeguy <85475922+nomeguy@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix type check for adapter in core_enforcer.dart Fix type check for FilteredAdapter using is operator Nov 18, 2025
Copilot AI requested a review from nomeguy November 18, 2025 15:21
@nomeguy nomeguy changed the title Fix type check for FilteredAdapter using is operator feat: fix type check for FilteredAdapter using is operator Nov 18, 2025
@nomeguy nomeguy merged commit 92f9f54 into master Nov 18, 2025
7 of 8 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 18, 2025
# [1.7.0](v1.6.0...v1.7.0) (2025-11-18)

### Features

* fix type check for FilteredAdapter using `is` operator ([#67](#67)) ([22db549](22db549))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

wrong type check of adapter

3 participants